1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
3 declare void @use_i8(i8)
4 define i8 @mul_selectp2_x(i8 %x, i1 %c) {
5 ; CHECK-LABEL: @mul_selectp2_x(
6 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 2
7 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]]
8 ; CHECK-NEXT: ret i8 [[R]]
10 %s = select i1 %c, i8 2, i8 4
16 define i8 @mul_selectp2_x_propegate_nuw(i8 %x, i1 %c) {
17 ; CHECK-LABEL: @mul_selectp2_x_propegate_nuw(
18 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 2
19 ; CHECK-NEXT: [[R:%.*]] = shl nuw i8 [[X:%.*]], [[TMP1]]
20 ; CHECK-NEXT: ret i8 [[R]]
22 %s = select i1 %c, i8 2, i8 4
23 %r = mul nuw nsw i8 %s, %x
28 define i8 @mul_selectp2_x_multiuse_fixme(i8 %x, i1 %c) {
29 ; CHECK-LABEL: @mul_selectp2_x_multiuse_fixme(
30 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 4
31 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C]], i8 1, i8 2
32 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]]
33 ; CHECK-NEXT: call void @use_i8(i8 [[S]])
34 ; CHECK-NEXT: ret i8 [[R]]
36 %s = select i1 %c, i8 2, i8 4
38 call void @use_i8(i8 %s)
42 define i8 @mul_selectp2_x_non_const(i8 %x, i1 %c, i8 %yy) {
43 ; CHECK-LABEL: @mul_selectp2_x_non_const(
44 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 [[YY:%.*]]
45 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]]
46 ; CHECK-NEXT: ret i8 [[R]]
49 %s = select i1 %c, i8 2, i8 %y
54 define i8 @mul_selectp2_x_non_const_multiuse(i8 %x, i1 %c, i8 %yy) {
55 ; CHECK-LABEL: @mul_selectp2_x_non_const_multiuse(
56 ; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 1, [[YY:%.*]]
57 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 [[YY]]
58 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]]
59 ; CHECK-NEXT: call void @use_i8(i8 [[Y]])
60 ; CHECK-NEXT: ret i8 [[R]]
63 %s = select i1 %c, i8 2, i8 %y
65 call void @use_i8(i8 %y)
69 define i8 @mul_x_selectp2(i8 %xx, i1 %c) {
70 ; CHECK-LABEL: @mul_x_selectp2(
71 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]
72 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 3, i8 0
73 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[X]], [[TMP1]]
74 ; CHECK-NEXT: ret i8 [[R]]
77 %s = select i1 %c, i8 8, i8 1
82 define i8 @mul_select_nonp2_x_fail(i8 %x, i1 %c) {
83 ; CHECK-LABEL: @mul_select_nonp2_x_fail(
84 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 5
85 ; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
86 ; CHECK-NEXT: ret i8 [[R]]
88 %s = select i1 %c, i8 2, i8 5
93 define <2 x i8> @mul_x_selectp2_vec(<2 x i8> %xx, i1 %c) {
94 ; CHECK-LABEL: @mul_x_selectp2_vec(
95 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX:%.*]], [[XX]]
96 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], <2 x i8> <i8 3, i8 4>, <2 x i8> <i8 2, i8 0>
97 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i8> [[X]], [[TMP1]]
98 ; CHECK-NEXT: ret <2 x i8> [[R]]
100 %x = mul <2 x i8> %xx, %xx
101 %s = select i1 %c, <2 x i8> <i8 8, i8 16>, <2 x i8> <i8 4, i8 1>
102 %r = mul <2 x i8> %x, %s
107 define i8 @shl_add_log_may_cause_poison_pr62175_fail(i8 %x, i8 %y) {
108 ; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_fail(
109 ; CHECK-NEXT: [[SHL:%.*]] = shl i8 4, [[X:%.*]]
110 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[SHL]], [[Y:%.*]]
111 ; CHECK-NEXT: ret i8 [[MUL]]
114 %mul = mul i8 %y, %shl
118 define i8 @shl_add_log_may_cause_poison_pr62175_with_nuw(i8 %x, i8 %y) {
119 ; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_with_nuw(
120 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 2
121 ; CHECK-NEXT: [[MUL:%.*]] = shl i8 [[Y:%.*]], [[TMP1]]
122 ; CHECK-NEXT: ret i8 [[MUL]]
124 %shl = shl nuw i8 4, %x
125 %mul = mul i8 %y, %shl
129 define i8 @shl_add_log_may_cause_poison_pr62175_with_nsw(i8 %x, i8 %y) {
130 ; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_with_nsw(
131 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 2
132 ; CHECK-NEXT: [[MUL:%.*]] = shl i8 [[Y:%.*]], [[TMP1]]
133 ; CHECK-NEXT: ret i8 [[MUL]]
135 %shl = shl nsw i8 4, %x
136 %mul = mul i8 %y, %shl