[NFC][InstSimplify] Add one more test for unneeded 'and'
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 20 Apr 2021 19:47:03 +0000 (22:47 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 20 Apr 2021 21:31:46 +0000 (00:31 +0300)
llvm/test/Transforms/InstSimplify/AndOrXor.ll

index 2e364a7..ee94d2f 100644 (file)
@@ -1186,3 +1186,29 @@ define i8 @xor_add_sub_wrong_op(i8 %x) {
   %r = xor i8 %a, %s
   ret i8 %r
 }
+
+; `and` isn't needed if it doesn't actually change any bits.
+define i8 @noop_and_t0(i8 %x) {
+; CHECK-LABEL: @noop_and_t0(
+; CHECK-NEXT:    [[A:%.*]] = shl i8 [[X:%.*]], 3
+; CHECK-NEXT:    [[B:%.*]] = lshr i8 [[A]], 2
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[B]], 62
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a = shl i8 %x, 3
+  %b = lshr i8 %a, 2
+  %r = and i8 %b, 62
+  ret i8 %r
+}
+define i8 @noop_and_t1(i8 %x) {
+; CHECK-LABEL: @noop_and_t1(
+; CHECK-NEXT:    [[A:%.*]] = shl i8 [[X:%.*]], 3
+; CHECK-NEXT:    [[B:%.*]] = lshr i8 [[A]], 2
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[B]], 126
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a = shl i8 %x, 3
+  %b = lshr i8 %a, 2
+  %r = and i8 %b, 126
+  ret i8 %r
+}