@@ -19,41 +19,57 @@ define i64 @narrow_add(i64 noundef %a, i64 noundef %b) {
1919 ret i64 %add
2020}
2121
22+ define i64 @narrow_add_1 (i64 noundef %a , i64 noundef %b ) {
23+ ; CHECK-LABEL: define i64 @narrow_add_1(
24+ ; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
25+ ; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 2147483647
26+ ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2147483648
27+ ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[ZEXT0]] to i32
28+ ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[ZEXT1]] to i32
29+ ; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP1]], [[TMP2]]
30+ ; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
31+ ; CHECK-NEXT: ret i64 [[TMP4]]
32+ ;
33+ %zext0 = and i64 %a , 2147483647
34+ %zext1 = and i64 %b , 2147483648
35+ %add = add i64 %zext0 , %zext1
36+ ret i64 %add
37+ }
38+
2239define i64 @narrow_mul (i64 noundef %a , i64 noundef %b ) {
2340; CHECK-LABEL: define i64 @narrow_mul(
2441; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
2542; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 2147483647
26- ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2147483647
43+ ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 0
2744; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[ZEXT0]] to i32
2845; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[ZEXT1]] to i32
2946; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP1]], [[TMP2]]
3047; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
3148; CHECK-NEXT: ret i64 [[TMP4]]
3249;
3350 %zext0 = and i64 %a , 2147483647
34- %zext1 = and i64 %b , 2147483647
51+ %zext1 = and i64 %b , 0
3552 %mul = mul i64 %zext0 , %zext1
3653 ret i64 %mul
3754}
3855
39- define i64 @narrow_sub (i64 noundef %a , i64 noundef %b ) {
40- ; CHECK-LABEL: define i64 @narrow_sub (
56+ define i64 @narrow_mul_1 (i64 noundef %a , i64 noundef %b ) {
57+ ; CHECK-LABEL: define i64 @narrow_mul_1 (
4158; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
4259; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 2147483647
43- ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2147483647
60+ ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2
4461; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[ZEXT0]] to i32
4562; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[ZEXT1]] to i32
4663; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP1]], [[TMP2]]
4764; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
4865; CHECK-NEXT: ret i64 [[TMP4]]
4966;
5067 %zext0 = and i64 %a , 2147483647
51- %zext1 = and i64 %b , 2147483647
52- %sub = sub i64 %zext0 , %zext1
53- ret i64 %sub
68+ %zext1 = and i64 %b , 2
69+ %mul = mul i64 %zext0 , %zext1
70+ ret i64 %mul
5471}
5572
56-
5773define i64 @no_narrow_add (i64 noundef %a , i64 noundef %b ) {
5874; CHECK-LABEL: define i64 @no_narrow_add(
5975; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
@@ -68,30 +84,30 @@ define i64 @no_narrow_add(i64 noundef %a, i64 noundef %b) {
6884 ret i64 %add
6985}
7086
87+ define i64 @no_narrow_add_1 (i64 noundef %a , i64 noundef %b ) {
88+ ; CHECK-LABEL: define i64 @no_narrow_add_1(
89+ ; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
90+ ; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 4294967295
91+ ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 1
92+ ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[ZEXT0]], [[ZEXT1]]
93+ ; CHECK-NEXT: ret i64 [[ADD]]
94+ ;
95+ %zext0 = and i64 %a , 4294967295
96+ %zext1 = and i64 %b , 1
97+ %add = add i64 %zext0 , %zext1
98+ ret i64 %add
99+ }
100+
71101define i64 @no_narrow_mul (i64 noundef %a , i64 noundef %b ) {
72102; CHECK-LABEL: define i64 @no_narrow_mul(
73103; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
74104; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 2147483648
75- ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2147483648
105+ ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2
76106; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[ZEXT0]], [[ZEXT1]]
77107; CHECK-NEXT: ret i64 [[MUL]]
78108;
79109 %zext0 = and i64 %a , 2147483648
80- %zext1 = and i64 %b , 2147483648
110+ %zext1 = and i64 %b , 2
81111 %mul = mul i64 %zext0 , %zext1
82112 ret i64 %mul
83113}
84-
85- define i64 @no_narrow_sub (i64 noundef %a , i64 noundef %b ) {
86- ; CHECK-LABEL: define i64 @no_narrow_sub(
87- ; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
88- ; CHECK-NEXT: [[ZEXT0:%.*]] = and i64 [[A]], 2147483648
89- ; CHECK-NEXT: [[ZEXT1:%.*]] = and i64 [[B]], 2147483648
90- ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[ZEXT0]], [[ZEXT1]]
91- ; CHECK-NEXT: ret i64 [[SUB]]
92- ;
93- %zext0 = and i64 %a , 2147483648
94- %zext1 = and i64 %b , 2147483648
95- %sub = sub i64 %zext0 , %zext1
96- ret i64 %sub
97- }
0 commit comments