[InstCombine] add tests for sub with masked bits; NFC
authorSanjay Patel <spatel@rotateright.com>
Fri, 13 Nov 2020 00:44:13 +0000 (19:44 -0500)
committerSanjay Patel <spatel@rotateright.com>
Fri, 13 Nov 2020 01:10:28 +0000 (20:10 -0500)
llvm/test/Transforms/InstCombine/sub.ll

index 98d8a9e..d703004 100644 (file)
@@ -1460,3 +1460,44 @@ define i8 @sub_add_sub_reassoc_use2(i8 %w, i8 %x, i8 %y, i8 %z) {
   %s2 = sub i8 %a, %z
   ret i8 %s2
 }
+
+define i8 @sub_mask_lowbits(i8 %x) {
+; CHECK-LABEL: @sub_mask_lowbits(
+; CHECK-NEXT:    [[A1:%.*]] = add i8 [[X:%.*]], -108
+; CHECK-NEXT:    [[A2:%.*]] = and i8 [[X]], 3
+; CHECK-NEXT:    [[R:%.*]] = sub i8 [[A1]], [[A2]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a1 = add i8 %x, 148 ; 0x94
+  %a2 = and i8 %x, 3
+  %r = sub i8 %a1, %a2
+  ret i8 %r
+}
+
+define i8 @sub_not_mask_lowbits(i8 %x) {
+; CHECK-LABEL: @sub_not_mask_lowbits(
+; CHECK-NEXT:    [[A1:%.*]] = add i8 [[X:%.*]], 4
+; CHECK-NEXT:    [[A2:%.*]] = and i8 [[X]], 7
+; CHECK-NEXT:    [[R:%.*]] = sub i8 [[A1]], [[A2]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %a1 = add i8 %x, 4
+  %a2 = and i8 %x, 7
+  %r = sub i8 %a1, %a2
+  ret i8 %r
+}
+
+define <2 x i8> @sub_mask_lowbits_splat_extra_use(<2 x i8> %x, <2 x i8>* %p) {
+; CHECK-LABEL: @sub_mask_lowbits_splat_extra_use(
+; CHECK-NEXT:    [[A1:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 -64>
+; CHECK-NEXT:    [[A2:%.*]] = and <2 x i8> [[X]], <i8 10, i8 10>
+; CHECK-NEXT:    store <2 x i8> [[A2]], <2 x i8>* [[P:%.*]], align 2
+; CHECK-NEXT:    [[R:%.*]] = sub <2 x i8> [[A1]], [[A2]]
+; CHECK-NEXT:    ret <2 x i8> [[R]]
+;
+  %a1 = add <2 x i8> %x, <i8 192, i8 192> ; 0xc0
+  %a2 = and <2 x i8> %x, <i8 10, i8 10>   ; 0x0a
+  store <2 x i8> %a2, <2 x i8>* %p
+  %r = sub <2 x i8> %a1, %a2
+  ret <2 x i8> %r
+}