diff --git a/llvm/test/Transforms/InstCombine/add-shift.ll b/llvm/test/Transforms/InstCombine/add-shift.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/add-shift.ll @@ -0,0 +1,64 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3 +; RUN: opt < %s -passes=instcombine -S | FileCheck %s +define i8 @flip_add_of_shift_neg(i8 %v, i8 %sh, i8 %x) { +; CHECK-LABEL: define i8 @flip_add_of_shift_neg +; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) { +; CHECK-NEXT: [[NV:%.*]] = sub i8 0, [[V]] +; CHECK-NEXT: [[SV:%.*]] = shl nuw nsw i8 [[NV]], [[SH]] +; CHECK-NEXT: [[R:%.*]] = add i8 [[SV]], [[X]] +; CHECK-NEXT: ret i8 [[R]] +; + %nv = sub i8 0, %v + %sv = shl nuw nsw i8 %nv, %sh + %r = add i8 %sv, %x + ret i8 %r +} + +define <2 x i8> @flip_add_of_shift_neg_vec(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) { +; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec +; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) { +; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]] +; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]] +; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]] +; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %x = mul <2 x i8> %xx, %xx + %nv = sub <2 x i8> zeroinitializer, %v + %sv = shl <2 x i8> %nv, %sh + %r = add <2 x i8> %x, %sv + ret <2 x i8> %r +} + +define i8 @flip_add_of_shift_neg_fail_shr(i8 %v, i8 %sh, i8 %x) { +; CHECK-LABEL: define i8 @flip_add_of_shift_neg_fail_shr +; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) { +; CHECK-NEXT: [[NV:%.*]] = sub i8 0, [[V]] +; CHECK-NEXT: [[SV:%.*]] = lshr i8 [[NV]], [[SH]] +; CHECK-NEXT: [[R:%.*]] = add i8 [[SV]], [[X]] +; CHECK-NEXT: ret i8 [[R]] +; + %nv = sub i8 0, %v + %sv = lshr i8 %nv, %sh + %r = add i8 %sv, %x + ret i8 %r +} + +declare void @use.v2i8(<2 x i8>) +define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) { +; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse +; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) { +; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]] +; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]] +; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]] +; CHECK-NEXT: call void @use.v2i8(<2 x i8> [[NV]]) +; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %x = mul <2 x i8> %xx, %xx + %nv = sub <2 x i8> zeroinitializer, %v + %sv = shl <2 x i8> %nv, %sh + call void @use.v2i8(<2 x i8> %nv) + %r = add <2 x i8> %x, %sv + ret <2 x i8> %r +}