[llvm] e536e2c - [InstCombine] Add additional tests for select value equivalence fold (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 21 06:47:52 PST 2022


Author: Nikita Popov
Date: 2022-12-21T15:47:40+01:00
New Revision: e536e2ca35361cdba935ca646d208784554e60d9

URL: https://github.com/llvm/llvm-project/commit/e536e2ca35361cdba935ca646d208784554e60d9
DIFF: https://github.com/llvm/llvm-project/commit/e536e2ca35361cdba935ca646d208784554e60d9.diff

LOG: [InstCombine] Add additional tests for select value equivalence fold (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/select-binop-cmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/select-binop-cmp.ll b/llvm/test/Transforms/InstCombine/select-binop-cmp.ll
index e23461155dbf8..9d57e8bf49e1f 100644
--- a/llvm/test/Transforms/InstCombine/select-binop-cmp.ll
+++ b/llvm/test/Transforms/InstCombine/select-binop-cmp.ll
@@ -3,6 +3,7 @@
 
 declare void @use(<2 x i1>)
 declare void @use2(i1)
+declare void @use.i32(i32)
 
 define i32 @select_xor_icmp(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @select_xor_icmp(
@@ -648,7 +649,7 @@ define i32 @select_or_icmp_bad(i32 %x, i32 %y, i32 %z) {
 
 define i32 @select_lshr_icmp_const(i32 %x) {
 ; CHECK-LABEL: @select_lshr_icmp_const(
-; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 [[X:%.*]], 5
 ; CHECK-NEXT:    ret i32 [[B]]
 ;
   %A = icmp ugt i32 %x, 31
@@ -659,7 +660,7 @@ define i32 @select_lshr_icmp_const(i32 %x) {
 
 define i32 @select_lshr_icmp_const_reordered(i32 %x) {
 ; CHECK-LABEL: @select_lshr_icmp_const_reordered(
-; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 [[X:%.*]], 5
 ; CHECK-NEXT:    ret i32 [[B]]
 ;
   %A = icmp ult i32 %x, 32
@@ -670,7 +671,7 @@ define i32 @select_lshr_icmp_const_reordered(i32 %x) {
 
 define i32 @select_exact_lshr_icmp_const(i32 %x) {
 ; CHECK-LABEL: @select_exact_lshr_icmp_const(
-; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 [[X:%.*]], 5
 ; CHECK-NEXT:    ret i32 [[B]]
 ;
   %A = icmp ugt i32 %x, 31
@@ -681,8 +682,8 @@ define i32 @select_exact_lshr_icmp_const(i32 %x) {
 
 define i32 @select_lshr_icmp_const_large_exact_range(i32 %x) {
 ; CHECK-LABEL: @select_lshr_icmp_const_large_exact_range(
-; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 63
-; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 [[X:%.*]], 63
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 [[X]], 5
 ; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
 ; CHECK-NEXT:    ret i32 [[C]]
 ;
@@ -694,8 +695,8 @@ define i32 @select_lshr_icmp_const_large_exact_range(i32 %x) {
 
 define i32 @select_lshr_icmp_const_
diff erent_values(i32 %x, i32 %y) {
 ; CHECK-LABEL: @select_lshr_icmp_const_
diff erent_values(
-; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 31
-; CHECK-NEXT:    [[B:%.*]] = lshr i32 %y, 5
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 [[X:%.*]], 31
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 [[Y:%.*]], 5
 ; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
 ; CHECK-NEXT:    ret i32 [[C]]
 ;
@@ -1221,6 +1222,55 @@ define i32 @select_replace_nested(i32 %x, i32 %y, i32 %z) {
   ret i32 %s
 }
 
+define i32 @select_replace_nested_extra_use(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: @select_replace_nested_extra_use(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[Y:%.*]], [[X]]
+; CHECK-NEXT:    call void @use.i32(i32 [[SUB]])
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[SUB]], [[Z:%.*]]
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[C]], i32 [[ADD]], i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %c = icmp eq i32 %x, 0
+  %sub = sub i32 %y, %x
+  call void @use.i32(i32 %sub)
+  %add = add i32 %sub, %z
+  %s = select i1 %c, i32 %add, i32 %y
+  ret i32 %s
+}
+
+define i32 @select_replace_nested_no_simplify(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: @select_replace_nested_no_simplify(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 1
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[Y:%.*]], [[X]]
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[SUB]], [[Z:%.*]]
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[C]], i32 [[ADD]], i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %c = icmp eq i32 %x, 1
+  %sub = sub i32 %y, %x
+  %add = add i32 %sub, %z
+  %s = select i1 %c, i32 %add, i32 %y
+  ret i32 %s
+}
+
+define i32 @select_replace_deeply_nested(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: @select_replace_deeply_nested(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[Y:%.*]], [[X]]
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[SUB]], [[Z:%.*]]
+; CHECK-NEXT:    [[SHL:%.*]] = shl i32 [[ADD]], 1
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[C]], i32 [[SHL]], i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[S]]
+;
+  %c = icmp eq i32 %x, 0
+  %sub = sub i32 %y, %x
+  %add = add i32 %sub, %z
+  %shl = shl i32 %add, 1
+  %s = select i1 %c, i32 %shl, i32 %y
+  ret i32 %s
+}
+
 ; Do not replace with constant expressions. The profitability in this case is
 ; unclear, and such replacements have historically lead to infinite combine
 ; loops.


        


More information about the llvm-commits mailing list