1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 define i8 @flip_add_of_shift_neg(i8 %v, i8 %sh, i8 %x) {
4 ; CHECK-LABEL: define i8 @flip_add_of_shift_neg
5 ; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) {
6 ; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[V]], [[SH]]
7 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[TMP1]]
8 ; CHECK-NEXT: ret i8 [[R]]
11 %sv = shl nuw nsw i8 %nv, %sh
16 define <2 x i8> @flip_add_of_shift_neg_vec(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
17 ; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec
18 ; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
19 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
20 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[V]], [[SH]]
21 ; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[X]], [[TMP1]]
22 ; CHECK-NEXT: ret <2 x i8> [[R]]
24 %x = mul <2 x i8> %xx, %xx
25 %nv = sub <2 x i8> zeroinitializer, %v
26 %sv = shl <2 x i8> %nv, %sh
27 %r = add <2 x i8> %x, %sv
31 define i8 @flip_add_of_shift_neg_fail_shr(i8 %v, i8 %sh, i8 %x) {
32 ; CHECK-LABEL: define i8 @flip_add_of_shift_neg_fail_shr
33 ; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) {
34 ; CHECK-NEXT: [[NV:%.*]] = sub i8 0, [[V]]
35 ; CHECK-NEXT: [[SV:%.*]] = lshr i8 [[NV]], [[SH]]
36 ; CHECK-NEXT: [[R:%.*]] = add i8 [[SV]], [[X]]
37 ; CHECK-NEXT: ret i8 [[R]]
40 %sv = lshr i8 %nv, %sh
45 declare void @use.v2i8(<2 x i8>)
46 define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_neg(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
47 ; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_neg
48 ; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
49 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
50 ; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]]
51 ; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]]
52 ; CHECK-NEXT: call void @use.v2i8(<2 x i8> [[NV]])
53 ; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]]
54 ; CHECK-NEXT: ret <2 x i8> [[R]]
56 %x = mul <2 x i8> %xx, %xx
57 %nv = sub <2 x i8> zeroinitializer, %v
58 %sv = shl <2 x i8> %nv, %sh
59 call void @use.v2i8(<2 x i8> %nv)
60 %r = add <2 x i8> %x, %sv
64 define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_shift(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
65 ; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_shift
66 ; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
67 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
68 ; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]]
69 ; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]]
70 ; CHECK-NEXT: call void @use.v2i8(<2 x i8> [[SV]])
71 ; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]]
72 ; CHECK-NEXT: ret <2 x i8> [[R]]
74 %x = mul <2 x i8> %xx, %xx
75 %nv = sub <2 x i8> zeroinitializer, %v
76 %sv = shl <2 x i8> %nv, %sh
77 call void @use.v2i8(<2 x i8> %sv)
78 %r = add <2 x i8> %x, %sv