[llvm] 6bcc1fd - [InstCombine] add tests for lshr with mul; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 12:02:43 PST 2021


Author: Sanjay Patel
Date: 2021-02-10T15:02:31-05:00
New Revision: 6bcc1fd461eeeb7946184cbfe886eead9291919c

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

LOG: [InstCombine] add tests for lshr with mul; NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/lshr.ll b/llvm/test/Transforms/InstCombine/lshr.ll
index bcc980da190f..ea3d3de542d0 100644
--- a/llvm/test/Transforms/InstCombine/lshr.ll
+++ b/llvm/test/Transforms/InstCombine/lshr.ll
@@ -259,3 +259,62 @@ define <2 x i32> @narrow_lshr_constant(<2 x i8> %x, <2 x i8> %y) {
   %sh = lshr <2 x i32> %zx, <i32 3, i32 3>
   ret <2 x i32> %sh
 }
+
+define i32 @mul_splat_fold(i32 %x) {
+; CHECK-LABEL: @mul_splat_fold(
+; CHECK-NEXT:    [[M:%.*]] = mul nuw i32 [[X:%.*]], 65537
+; CHECK-NEXT:    [[T:%.*]] = lshr i32 [[M]], 16
+; CHECK-NEXT:    ret i32 [[T]]
+;
+  %m = mul nuw i32 %x, 65537
+  %t = lshr i32 %m, 16
+  ret i32 %t
+}
+
+declare void @usevec(<3 x i14>)
+
+define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
+; CHECK-LABEL: @mul_splat_fold_vec(
+; CHECK-NEXT:    [[M:%.*]] = mul nuw <3 x i14> [[X:%.*]], <i14 129, i14 129, i14 129>
+; CHECK-NEXT:    call void @usevec(<3 x i14> [[M]])
+; CHECK-NEXT:    [[T:%.*]] = lshr <3 x i14> [[M]], <i14 7, i14 7, i14 7>
+; CHECK-NEXT:    ret <3 x i14> [[T]]
+;
+  %m = mul nuw <3 x i14> %x, <i14 129, i14 129, i14 129>
+  call void @usevec(<3 x i14> %m)
+  %t = lshr <3 x i14> %m, <i14 7, i14 7, i14 7>
+  ret <3 x i14> %t
+}
+
+define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
+; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
+; CHECK-NEXT:    [[M:%.*]] = mul nuw i32 [[X:%.*]], 65538
+; CHECK-NEXT:    [[T:%.*]] = lshr i32 [[M]], 16
+; CHECK-NEXT:    ret i32 [[T]]
+;
+  %m = mul nuw i32 %x, 65538
+  %t = lshr i32 %m, 16
+  ret i32 %t
+}
+
+define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
+; CHECK-LABEL: @mul_splat_fold_wrong_lshr_const(
+; CHECK-NEXT:    [[M:%.*]] = mul nuw i32 [[X:%.*]], 65537
+; CHECK-NEXT:    [[T:%.*]] = lshr i32 [[M]], 15
+; CHECK-NEXT:    ret i32 [[T]]
+;
+  %m = mul nuw i32 %x, 65537
+  %t = lshr i32 %m, 15
+  ret i32 %t
+}
+
+define i32 @mul_splat_fold_no_nuw(i32 %x) {
+; CHECK-LABEL: @mul_splat_fold_no_nuw(
+; CHECK-NEXT:    [[M:%.*]] = mul nsw i32 [[X:%.*]], 65537
+; CHECK-NEXT:    [[T:%.*]] = lshr i32 [[M]], 16
+; CHECK-NEXT:    ret i32 [[T]]
+;
+  %m = mul nsw i32 %x, 65537
+  %t = lshr i32 %m, 16
+  ret i32 %t
+}


        


More information about the llvm-commits mailing list