diff --git a/llvm/test/Transforms/InstCombine/shl-bo.ll b/llvm/test/Transforms/InstCombine/shl-bo.ll index f581ca2cb628..2ac2211f5ab2 100644 --- a/llvm/test/Transforms/InstCombine/shl-bo.ll +++ b/llvm/test/Transforms/InstCombine/shl-bo.ll @@ -1,6 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s +declare void @use(i8) + define i8 @lshr_add(i8 %a, i8 %y) { ; CHECK-LABEL: @lshr_add( ; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42 @@ -149,6 +151,36 @@ define <2 x i8> @lshr_xor_commute_splat(<2 x i8> %a, <2 x i8> %y) { ret <2 x i8> %l } +define i8 @lshr_add_use1(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_add_use1( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 5 +; CHECK-NEXT: call void @use(i8 [[R]]) +; CHECK-NEXT: [[B:%.*]] = add i8 [[R]], [[X:%.*]] +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 5 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 5 + call void @use(i8 %r) + %b = add i8 %r, %x + %l = shl i8 %b, 5 + ret i8 %l +} + +define i8 @lshr_add_use2(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_add_use2( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 5 +; CHECK-NEXT: [[B:%.*]] = add i8 [[R]], [[X:%.*]] +; CHECK-NEXT: call void @use(i8 [[B]]) +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 5 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 5 + %b = add i8 %r, %x + call void @use(i8 %b) + %l = shl i8 %b, 5 + ret i8 %l +} + define i8 @lshr_and_add(i8 %a, i8 %y) { ; CHECK-LABEL: @lshr_and_add( ; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42 @@ -310,6 +342,114 @@ define <2 x i8> @lshr_and_xor_commute_splat(<2 x i8> %a, <2 x i8> %y) { ret <2 x i8> %l } +define i8 @lshr_and_add_use1(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use1( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: call void @use(i8 [[R]]) +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + call void @use(i8 %r) + %m = and i8 %r, 12 + %b = add i8 %x, %m + %l = shl i8 %b, 3 + ret i8 %l +} + +define i8 @lshr_and_add_use2(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use2( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: call void @use(i8 [[M]]) +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + %m = and i8 %r, 12 + call void @use(i8 %m) + %b = add i8 %x, %m + %l = shl i8 %b, 3 + ret i8 %l +} + +define i8 @lshr_and_add_use3(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use3( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: call void @use(i8 [[B]]) +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + %m = and i8 %r, 12 + %b = add i8 %x, %m + call void @use(i8 %b) + %l = shl i8 %b, 3 + ret i8 %l +} + +define i8 @lshr_and_add_use4(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use4( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: call void @use(i8 [[R]]) +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: call void @use(i8 [[M]]) +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + call void @use(i8 %r) + %m = and i8 %r, 12 + call void @use(i8 %m) + %b = add i8 %x, %m + %l = shl i8 %b, 3 + ret i8 %l +} + +define i8 @lshr_and_add_use5(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use5( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: call void @use(i8 [[M]]) +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: call void @use(i8 [[B]]) +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + %m = and i8 %r, 12 + call void @use(i8 %m) + %b = add i8 %x, %m + call void @use(i8 %b) + %l = shl i8 %b, 3 + ret i8 %l +} + +define i8 @lshr_and_add_use6(i8 %x, i8 %y) { +; CHECK-LABEL: @lshr_and_add_use6( +; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3 +; CHECK-NEXT: call void @use(i8 [[R]]) +; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12 +; CHECK-NEXT: call void @use(i8 [[M]]) +; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]] +; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3 +; CHECK-NEXT: ret i8 [[L]] +; + %r = lshr i8 %y, 3 + call void @use(i8 %r) + %m = and i8 %r, 12 + call void @use(i8 %m) + %b = add i8 %x, %m + %l = shl i8 %b, 3 + ret i8 %l +} + define <2 x i8> @lshr_add_shl_v2i8_undef(<2 x i8> %x, <2 x i8> %y) { ; CHECK-LABEL: @lshr_add_shl_v2i8_undef( ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i8> [[Y:%.*]],