[llvm] 95cd6ae - [InstCombine] Add tests for non-zero pow2 of shl with nowrap flags (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 08:00:59 PDT 2023


Author: Nikita Popov
Date: 2023-08-07T17:00:50+02:00
New Revision: 95cd6aedc152d9628a3f1404e18ec39989bc7ff2

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

LOG: [InstCombine] Add tests for non-zero pow2 of shl with nowrap flags (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/icmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 7fd7b8602f12c8..b0fcdc572f2137 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -1868,6 +1868,51 @@ define i1 @icmp_and_shl_neg_ne_0(i32 %A, i32 %B) {
   ret i1 %cmp
 }
 
+define i1 @icmp_and_shl_neg_ne_0_shl2_no_flags(i32 %A, i32 %B) {
+; CHECK-LABEL: @icmp_and_shl_neg_ne_0_shl2_no_flags(
+; CHECK-NEXT:    [[NEG:%.*]] = xor i32 [[A:%.*]], -1
+; CHECK-NEXT:    [[SHL:%.*]] = shl i32 2, [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = and i32 [[SHL]], [[NEG]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[AND]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %neg = xor i32 %A, -1
+  %shl = shl i32 2, %B
+  %and = and i32 %shl, %neg
+  %cmp = icmp ne i32 %and, 0
+  ret i1 %cmp
+}
+
+define i1 @icmp_and_shl_neg_ne_0_shl2_nuw(i32 %A, i32 %B) {
+; CHECK-LABEL: @icmp_and_shl_neg_ne_0_shl2_nuw(
+; CHECK-NEXT:    [[NEG:%.*]] = xor i32 [[A:%.*]], -1
+; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i32 2, [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = and i32 [[SHL]], [[NEG]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[AND]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %neg = xor i32 %A, -1
+  %shl = shl nuw i32 2, %B
+  %and = and i32 %shl, %neg
+  %cmp = icmp ne i32 %and, 0
+  ret i1 %cmp
+}
+
+define i1 @icmp_and_shl_neg_ne_0_shl2_nsw(i32 %A, i32 %B) {
+; CHECK-LABEL: @icmp_and_shl_neg_ne_0_shl2_nsw(
+; CHECK-NEXT:    [[NEG:%.*]] = xor i32 [[A:%.*]], -1
+; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i32 2, [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = and i32 [[SHL]], [[NEG]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[AND]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %neg = xor i32 %A, -1
+  %shl = shl nuw i32 2, %B
+  %and = and i32 %shl, %neg
+  %cmp = icmp ne i32 %and, 0
+  ret i1 %cmp
+}
+
 define i1 @icmp_and_shl_neg_eq_0(i32 %A, i32 %B) {
 ; CHECK-LABEL: @icmp_and_shl_neg_eq_0(
 ; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]


        


More information about the llvm-commits mailing list