From 6bcc1fd461eeeb7946184cbfe886eead9291919c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 10 Feb 2021 14:40:08 -0500 Subject: [PATCH] [InstCombine] add tests for lshr with mul; NFC --- llvm/test/Transforms/InstCombine/lshr.ll | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) 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, 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:%.*]], +; CHECK-NEXT: call void @usevec(<3 x i14> [[M]]) +; CHECK-NEXT: [[T:%.*]] = lshr <3 x i14> [[M]], +; CHECK-NEXT: ret <3 x i14> [[T]] +; + %m = mul nuw <3 x i14> %x, + call void @usevec(<3 x i14> %m) + %t = lshr <3 x i14> %m, + 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 +}