1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64)
5 declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)
6 declare { i1, i1 } @llvm.umul.with.overflow.i1(i1, i1)
7 declare { <2 x i1>, <2 x i1> } @llvm.umul.with.overflow.v2i1(<2 x i1>, <2 x i1>)
9 define i1 @test_generic(i64 %a, i64 %b) {
10 ; CHECK-LABEL: @test_generic(
11 ; CHECK-NEXT: [[RES:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[A:%.*]], i64 [[B:%.*]])
12 ; CHECK-NEXT: [[OVERFLOW:%.*]] = extractvalue { i64, i1 } [[RES]], 1
13 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
15 %res = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
16 %overflow = extractvalue { i64, i1 } %res, 1
20 define i1 @test_constant0(i8 %a) {
21 ; CHECK-LABEL: @test_constant0(
22 ; CHECK-NEXT: ret i1 false
24 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 0)
25 %overflow = extractvalue { i8, i1 } %res, 1
29 define i1 @test_constant1(i8 %a) {
30 ; CHECK-LABEL: @test_constant1(
31 ; CHECK-NEXT: ret i1 false
33 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 1)
34 %overflow = extractvalue { i8, i1 } %res, 1
38 define i1 @test_constant2(i8 %a) {
39 ; CHECK-LABEL: @test_constant2(
40 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp slt i8 [[A:%.*]], 0
41 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
43 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 2)
44 %overflow = extractvalue { i8, i1 } %res, 1
48 define i1 @test_constant3(i8 %a) {
49 ; CHECK-LABEL: @test_constant3(
50 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 85
51 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
53 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 3)
54 %overflow = extractvalue { i8, i1 } %res, 1
58 define i1 @test_constant4(i8 %a) {
59 ; CHECK-LABEL: @test_constant4(
60 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 63
61 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
63 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 4)
64 %overflow = extractvalue { i8, i1 } %res, 1
69 define i1 @test_constant127(i8 %a) {
70 ; CHECK-LABEL: @test_constant127(
71 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 2
72 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
74 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 127)
75 %overflow = extractvalue { i8, i1 } %res, 1
79 define i1 @test_constant128(i8 %a) {
80 ; CHECK-LABEL: @test_constant128(
81 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 1
82 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
84 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 128)
85 %overflow = extractvalue { i8, i1 } %res, 1
89 define i1 @test_constant255(i8 %a) {
90 ; CHECK-LABEL: @test_constant255(
91 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 1
92 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
94 %res = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 255)
95 %overflow = extractvalue { i8, i1 } %res, 1
99 define i1 @i1_res(i1 %x, i1 %y) {
100 ; CHECK-LABEL: @i1_res(
101 ; CHECK-NEXT: [[M:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
102 ; CHECK-NEXT: ret i1 [[M]]
104 %m = call {i1, i1} @llvm.umul.with.overflow.i1(i1 %x, i1 %y)
105 %r = extractvalue {i1, i1} %m, 0
109 define <2 x i1> @v2i1_res(<2 x i1> %x, <2 x i1> %y) {
110 ; CHECK-LABEL: @v2i1_res(
111 ; CHECK-NEXT: [[M:%.*]] = and <2 x i1> [[X:%.*]], [[Y:%.*]]
112 ; CHECK-NEXT: ret <2 x i1> [[M]]
114 %m = call {<2 x i1>, <2 x i1>} @llvm.umul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> %y)
115 %r = extractvalue {<2 x i1>, <2 x i1>} %m, 0
119 define i1 @i1_res_by_one(i1 %x) {
120 ; CHECK-LABEL: @i1_res_by_one(
121 ; CHECK-NEXT: ret i1 [[X:%.*]]
123 %m = call {i1, i1} @llvm.umul.with.overflow.i1(i1 %x, i1 1)
124 %r = extractvalue {i1, i1} %m, 0
128 define <2 x i1> @v2i1_res_by_one(<2 x i1> %x) {
129 ; CHECK-LABEL: @v2i1_res_by_one(
130 ; CHECK-NEXT: ret <2 x i1> [[X:%.*]]
132 %m = call {<2 x i1>, <2 x i1>} @llvm.umul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> <i1 1, i1 1>)
133 %r = extractvalue {<2 x i1>, <2 x i1>} %m, 0
137 define i1 @i1_ov(i1 %x, i1 %y) {
138 ; CHECK-LABEL: @i1_ov(
139 ; CHECK-NEXT: ret i1 false
141 %m = call {i1, i1} @llvm.umul.with.overflow.i1(i1 %x, i1 %y)
142 %ov = extractvalue {i1, i1} %m, 1
146 define <2 x i1> @v2i1_ov(<2 x i1> %x, <2 x i1> %y) {
147 ; CHECK-LABEL: @v2i1_ov(
148 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
150 %m = call {<2 x i1>, <2 x i1>} @llvm.umul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> %y)
151 %ov = extractvalue {<2 x i1>, <2 x i1>} %m, 1
155 define i1 @i1_ov_by_one(i1 %x) {
156 ; CHECK-LABEL: @i1_ov_by_one(
157 ; CHECK-NEXT: ret i1 false
159 %m = call {i1, i1} @llvm.umul.with.overflow.i1(i1 %x, i1 1)
160 %ov = extractvalue {i1, i1} %m, 1
164 define <2 x i1> @v2i1_ov_by_one(<2 x i1> %x) {
165 ; CHECK-LABEL: @v2i1_ov_by_one(
166 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
168 %m = call {<2 x i1>, <2 x i1>} @llvm.umul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> <i1 1, i1 1>)
169 %ov = extractvalue {<2 x i1>, <2 x i1>} %m, 1