[llvm] c34a99f - [InstCombine] Add extra use tests for abs canonicalization (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 12:13:57 PDT 2020
Author: Nikita Popov
Date: 2020-09-12T21:13:46+02:00
New Revision: c34a99fe589b870354c9a7863b79d882c74f7d50
URL: https://github.com/llvm/llvm-project/commit/c34a99fe589b870354c9a7863b79d882c74f7d50
DIFF: https://github.com/llvm/llvm-project/commit/c34a99fe589b870354c9a7863b79d882c74f7d50.diff
LOG: [InstCombine] Add extra use tests for abs canonicalization (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/abs-1.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/abs-1.ll b/llvm/test/Transforms/InstCombine/abs-1.ll
index 08cab94e3dfc..f879b165f4b8 100644
--- a/llvm/test/Transforms/InstCombine/abs-1.ll
+++ b/llvm/test/Transforms/InstCombine/abs-1.ll
@@ -461,6 +461,7 @@ define i8 @shifty_abs_commute3(i8 %x) {
; Negative test - don't transform if it would increase instruction count.
declare void @extra_use(i8)
+declare void @extra_use_i1(i1)
define i8 @shifty_abs_too_many_uses(i8 %x) {
; CHECK-LABEL: @shifty_abs_too_many_uses(
@@ -534,8 +535,8 @@ define i8 @negate_abs(i8 %x) {
; CHECK-LABEL: @negate_abs(
; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X]], 0
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
-; CHECK-NEXT: ret i8 [[S]]
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: ret i8 [[TMP1]]
;
%n = sub i8 0, %x
%c = icmp slt i8 %x, 0
@@ -548,8 +549,8 @@ define <2 x i8> @negate_nabs(<2 x i8> %x) {
; CHECK-LABEL: @negate_nabs(
; CHECK-NEXT: [[N:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X]], zeroinitializer
-; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[N]], <2 x i8> [[X]]
-; CHECK-NEXT: ret <2 x i8> [[S]]
+; CHECK-NEXT: [[TMP1:%.*]] = select <2 x i1> [[C]], <2 x i8> [[N]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[TMP1]]
;
%n = sub <2 x i8> zeroinitializer, %x
%c = icmp slt <2 x i8> %x, zeroinitializer
@@ -647,3 +648,97 @@ define i64 @infinite_loop_constant_expression_abs(i64 %arg) {
%t3 = select i1 %t1, i64 %t2, i64 %t
ret i64 %t3
}
+
+define i8 @abs_extra_use_icmp(i8 %x) {
+; CHECK-LABEL: @abs_extra_use_icmp(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[N]], i8 [[X]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ call void @extra_use_i1(i1 %c)
+ %n = sub i8 0, %x
+ %s = select i1 %c, i8 %n, i8 %x
+ ret i8 %s
+}
+
+define i8 @abs_extra_use_sub(i8 %x) {
+; CHECK-LABEL: @abs_extra_use_sub(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: call void @extra_use(i8 [[N]])
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[N]], i8 [[X]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ %n = sub i8 0, %x
+ call void @extra_use(i8 %n)
+ %s = select i1 %c, i8 %n, i8 %x
+ ret i8 %s
+}
+
+define i8 @abs_extra_use_icmp_sub(i8 %x) {
+; CHECK-LABEL: @abs_extra_use_icmp_sub(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: call void @extra_use(i8 [[N]])
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[N]], i8 [[X]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ call void @extra_use_i1(i1 %c)
+ %n = sub i8 0, %x
+ call void @extra_use(i8 %n)
+ %s = select i1 %c, i8 %n, i8 %x
+ ret i8 %s
+}
+
+define i8 @nabs_extra_use_icmp(i8 %x) {
+; CHECK-LABEL: @nabs_extra_use_icmp(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ call void @extra_use_i1(i1 %c)
+ %n = sub i8 0, %x
+ %s = select i1 %c, i8 %x, i8 %n
+ ret i8 %s
+}
+
+define i8 @nabs_extra_use_sub(i8 %x) {
+; CHECK-LABEL: @nabs_extra_use_sub(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: call void @extra_use(i8 [[N]])
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ %n = sub i8 0, %x
+ call void @extra_use(i8 %n)
+ %s = select i1 %c, i8 %x, i8 %n
+ ret i8 %s
+}
+
+define i8 @nabs_extra_use_icmp_sub(i8 %x) {
+; CHECK-LABEL: @nabs_extra_use_icmp_sub(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
+; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: call void @extra_use(i8 [[N]])
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: ret i8 [[S]]
+;
+ %c = icmp slt i8 %x, 0
+ call void @extra_use_i1(i1 %c)
+ %n = sub i8 0, %x
+ call void @extra_use(i8 %n)
+ %s = select i1 %c, i8 %x, i8 %n
+ ret i8 %s
+}
More information about the llvm-commits
mailing list