[llvm] eecaa86 - [InstCombine] add tests for multi-use sub demanded bits: NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 11:14:54 PDT 2022


Author: Sanjay Patel
Date: 2022-09-21T14:13:05-04:00
New Revision: eecaa86314fc1145e4786b86c16a98cf3157dd1e

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

LOG: [InstCombine] add tests for multi-use sub demanded bits: NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index dcb10dfaf3fb..0c016e8f3a05 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -2068,3 +2068,52 @@ define i8 @mul_sub_common_factor_use(i8 %x, i8 %y) {
   %a = sub i8 %m, %x
   ret i8 %a
 }
+
+define i5 @demand_low_bits_uses(i8 %x, i8 %y) {
+; CHECK-LABEL: @demand_low_bits_uses(
+; CHECK-NEXT:    [[M:%.*]] = and i8 [[X:%.*]], 96
+; CHECK-NEXT:    [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
+; CHECK-NEXT:    call void @use8(i8 [[A]])
+; CHECK-NEXT:    [[R:%.*]] = trunc i8 [[A]] to i5
+; CHECK-NEXT:    ret i5 [[R]]
+;
+  %m = and i8 %x, 96 ; 0x60
+  %a = sub i8 %y, %m
+  call void @use8(i8 %a)
+  %r = trunc i8 %a to i5
+  ret i5 %r
+}
+
+; negative test - demands one more bit
+
+define i6 @demand_low_bits_uses_extra_bit(i8 %x, i8 %y) {
+; CHECK-LABEL: @demand_low_bits_uses_extra_bit(
+; CHECK-NEXT:    [[M:%.*]] = and i8 [[X:%.*]], 96
+; CHECK-NEXT:    [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
+; CHECK-NEXT:    call void @use8(i8 [[A]])
+; CHECK-NEXT:    [[R:%.*]] = trunc i8 [[A]] to i6
+; CHECK-NEXT:    ret i6 [[R]]
+;
+  %m = and i8 %x, 96 ; 0x60
+  %a = sub i8 %y, %m
+  call void @use8(i8 %a)
+  %r = trunc i8 %a to i6
+  ret i6 %r
+}
+
+define i8 @demand_low_bits_uses_commute(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @demand_low_bits_uses_commute(
+; CHECK-NEXT:    [[M:%.*]] = and i8 [[X:%.*]], -64
+; CHECK-NEXT:    [[A:%.*]] = sub i8 [[M]], [[Y:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[A]])
+; CHECK-NEXT:    [[S:%.*]] = sub i8 [[A]], [[Z:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = shl i8 [[S]], 2
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %m = and i8 %x, -64 ; 0xC0
+  %a = sub i8 %m, %y
+  call void @use8(i8 %a)
+  %s = sub i8 %a, %z
+  %r = shl i8 %s, 2
+  ret i8 %r
+}


        


More information about the llvm-commits mailing list