From a73973c9d4616679569010d800f89be650dafcb7 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 6 Sep 2021 09:30:44 -0400 Subject: [PATCH] [InstCombine] add test for shift-trunc-shift with extra uses; NFC The transform doesn't check for extra uses, so we have more instructions than we started with. --- .../shift-amount-reassociation-with-truncation-shl.ll | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll index 223b262..4b76207 100644 --- a/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll +++ b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll @@ -210,3 +210,21 @@ define i16 @t01(i32 %x) { %t2 = shl i16 %t1, ptrtoint (i16* @Y16 to i16) ret i16 %t2 } + +define i16 @shl_tr_shl_constant_shift_amount_uses(i32 %x) { +; CHECK-LABEL: @shl_tr_shl_constant_shift_amount_uses( +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X:%.*]], 3 +; CHECK-NEXT: call void @use32(i32 [[SHL]]) +; CHECK-NEXT: [[TR:%.*]] = trunc i32 [[SHL]] to i16 +; CHECK-NEXT: call void @use16(i16 [[TR]]) +; CHECK-NEXT: [[X_TR:%.*]] = trunc i32 [[X]] to i16 +; CHECK-NEXT: [[R:%.*]] = shl i16 [[X_TR]], 7 +; CHECK-NEXT: ret i16 [[R]] +; + %shl = shl i32 %x, 3 + call void @use32(i32 %shl) + %tr = trunc i32 %shl to i16 + call void @use16(i16 %tr) + %r = shl i16 %tr, 4 + ret i16 %r +} -- 2.7.4