[llvm] c1c3134 - [InstCombine] add tests for and-of-negated-lowbitmask; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 3 09:27:04 PDT 2022


Author: Sanjay Patel
Date: 2022-07-03T12:25:25-04:00
New Revision: c1c3134ac422c51c635ea7f28c37838b3805c912

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

LOG: [InstCombine] add tests for and-of-negated-lowbitmask; NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll
index 6143e61c783b..9cf9c720473c 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -2167,3 +2167,61 @@ define <3 x i16> @lshr_shl_pow2_const_case1_undef3_vec(<3 x i16> %x) {
   %r = and <3 x i16> %shl, <i16 undef, i16 128, i16 128>
   ret <3 x i16> %r
 }
+
+define i8 @negate_lowbitmask(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_lowbitmask(
+; CHECK-NEXT:    [[A:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[N:%.*]] = sub nsw i8 0, [[A]]
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[N]], [[Y:%.*]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a = and i8 %x, 1
+  %n = sub i8 0, %a
+  %r = and i8 %n, %y
+  ret i8 %r
+}
+
+define <2 x i5> @negate_lowbitmask_commute(<2 x i5> %x, <2 x i5> %p) {
+; CHECK-LABEL: @negate_lowbitmask_commute(
+; CHECK-NEXT:    [[Y:%.*]] = mul <2 x i5> [[P:%.*]], [[P]]
+; CHECK-NEXT:    [[A:%.*]] = and <2 x i5> [[X:%.*]], <i5 1, i5 poison>
+; CHECK-NEXT:    [[N:%.*]] = sub <2 x i5> <i5 poison, i5 0>, [[A]]
+; CHECK-NEXT:    [[R:%.*]] = and <2 x i5> [[Y]], [[N]]
+; CHECK-NEXT:    ret <2 x i5> [[R]]
+;
+  %y = mul <2 x i5> %p, %p ; thwart complexity-based canonicalization
+  %a = and <2 x i5> %x, <i5 1, i5 poison>
+  %n = sub <2 x i5> <i5 poison, i5 0>, %a
+  %r = and <2 x i5> %y, %n
+  ret <2 x i5> %r
+}
+
+define i8 @negate_lowbitmask_use1(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_lowbitmask_use1(
+; CHECK-NEXT:    [[A:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT:    call void @use8(i8 [[A]])
+; CHECK-NEXT:    [[N:%.*]] = sub nsw i8 0, [[A]]
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[N]], [[Y:%.*]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a = and i8 %x, 1
+  call void @use8(i8 %a)
+  %n = sub i8 0, %a
+  %r = and i8 %n, %y
+  ret i8 %r
+}
+
+define i8 @negate_lowbitmask_use2(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_lowbitmask_use2(
+; CHECK-NEXT:    [[A:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[N:%.*]] = sub nsw i8 0, [[A]]
+; CHECK-NEXT:    call void @use8(i8 [[N]])
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[N]], [[Y:%.*]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a = and i8 %x, 1
+  %n = sub i8 0, %a
+  call void @use8(i8 %n)
+  %r = and i8 %n, %y
+  ret i8 %r
+}


        


More information about the llvm-commits mailing list