[llvm] 463e9be - [InstCombine] Add tests for (X << Z) / (X * Y) -> (1 << Z) / Y. nfc

Chenbing Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 01:08:31 PST 2022


Author: Chenbing Zheng
Date: 2022-12-07T17:06:11+08:00
New Revision: 463e9be1d4cd40ca3235a8b4a5aaccd8f847162d

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

LOG: [InstCombine] Add tests for (X << Z) / (X * Y) -> (1 << Z) / Y. nfc

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/div-shift.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/div-shift.ll b/llvm/test/Transforms/InstCombine/div-shift.ll
index 084b596754cf8..2831a808918ee 100644
--- a/llvm/test/Transforms/InstCombine/div-shift.ll
+++ b/llvm/test/Transforms/InstCombine/div-shift.ll
@@ -543,6 +543,34 @@ define i5 @udiv_shl_mul_nuw(i5 %x, i5 %y, i5 %z) {
   ret i5 %d
 }
 
+define i5 @udiv_shl_mul_nuw_swap(i5 %x, i5 %y, i5 %z) {
+; CHECK-LABEL: @udiv_shl_mul_nuw_swap(
+; CHECK-NEXT:    [[M1:%.*]] = shl nuw i5 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[M2:%.*]] = mul nuw i5 [[Y:%.*]], [[X]]
+; CHECK-NEXT:    [[D:%.*]] = udiv i5 [[M1]], [[M2]]
+; CHECK-NEXT:    ret i5 [[D]]
+;
+  %m1 = shl nuw i5 %x, %z
+  %m2 = mul nuw i5 %y, %x
+  %d = udiv i5 %m1, %m2
+  ret i5 %d
+}
+
+; negative test - sdiv
+
+define i5 @sdiv_shl_mul_nuw(i5 %x, i5 %y, i5 %z) {
+; CHECK-LABEL: @sdiv_shl_mul_nuw(
+; CHECK-NEXT:    [[M1:%.*]] = shl nuw i5 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[M2:%.*]] = mul nuw i5 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[D:%.*]] = sdiv i5 [[M1]], [[M2]]
+; CHECK-NEXT:    ret i5 [[D]]
+;
+  %m1 = shl nuw i5 %x, %z
+  %m2 = mul nuw i5 %x, %y
+  %d = sdiv i5 %m1, %m2
+  ret i5 %d
+}
+
 ; negative test - wrong no-wrap
 
 define i5 @udiv_mul_shl_missing_nsw1(i5 %x, i5 %y, i5 %z) {


        


More information about the llvm-commits mailing list