1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s
4 declare i8 @llvm.sadd.sat.i8(i8, i8)
5 declare i8 @llvm.ssub.sat.i8(i8, i8)
6 declare i8 @llvm.uadd.sat.i8(i8, i8)
7 declare i8 @llvm.usub.sat.i8(i8, i8)
9 define i1 @uadd_sat_overflow(i8 %x, i8 %y) {
10 ; CHECK-LABEL: @uadd_sat_overflow(
11 ; CHECK-NEXT: ret i1 false
15 %exp = call i8 @llvm.uadd.sat.i8(i8 %lhs, i8 %rhs)
16 %r = icmp eq i8 %exp, 254
20 define i1 @uadd_sat_overflow_fail(i8 %x, i8 %y) {
21 ; CHECK-LABEL: @uadd_sat_overflow_fail(
22 ; CHECK-NEXT: [[LHS:%.*]] = or i8 [[X:%.*]], -128
23 ; CHECK-NEXT: [[RHS:%.*]] = or i8 [[Y:%.*]], 126
24 ; CHECK-NEXT: [[EXP:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[LHS]], i8 [[RHS]])
25 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[EXP]], -2
26 ; CHECK-NEXT: ret i1 [[R]]
30 %exp = call i8 @llvm.uadd.sat.i8(i8 %lhs, i8 %rhs)
31 %r = icmp eq i8 %exp, 254
35 define i1 @usub_sat_overflow(i8 %x, i8 %y) {
36 ; CHECK-LABEL: @usub_sat_overflow(
37 ; CHECK-NEXT: ret i1 false
41 %exp = call i8 @llvm.usub.sat.i8(i8 %lhs, i8 %rhs)
42 %r = icmp eq i8 %exp, 1
46 define i1 @usub_sat_overflow_fail(i8 %x, i8 %y) {
47 ; CHECK-LABEL: @usub_sat_overflow_fail(
48 ; CHECK-NEXT: [[LHS:%.*]] = and i8 [[X:%.*]], 127
49 ; CHECK-NEXT: [[RHS:%.*]] = or i8 [[Y:%.*]], 126
50 ; CHECK-NEXT: [[EXP:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[LHS]], i8 [[RHS]])
51 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[EXP]], 1
52 ; CHECK-NEXT: ret i1 [[R]]
56 %exp = call i8 @llvm.usub.sat.i8(i8 %lhs, i8 %rhs)
57 %r = icmp eq i8 %exp, 1
61 define i1 @sadd_sat_overflow_pos(i8 %x, i8 %y) {
62 ; CHECK-LABEL: @sadd_sat_overflow_pos(
63 ; CHECK-NEXT: ret i1 false
69 %exp = call i8 @llvm.sadd.sat.i8(i8 %lhs, i8 %rhs)
70 %r = icmp eq i8 %exp, 128
74 define i1 @sadd_sat_low_bits(i8 %x, i8 %y) {
75 ; CHECK-LABEL: @sadd_sat_low_bits(
76 ; CHECK-NEXT: ret i1 false
82 %exp = call i8 @llvm.sadd.sat.i8(i8 %lhs, i8 %rhs)
84 %r = icmp eq i8 %and, 0
88 define i1 @sadd_sat_fail_may_overflow(i8 %x, i8 %y) {
89 ; CHECK-LABEL: @sadd_sat_fail_may_overflow(
90 ; CHECK-NEXT: [[LHS:%.*]] = or i8 [[X:%.*]], 1
91 ; CHECK-NEXT: [[RHS:%.*]] = and i8 [[Y:%.*]], -2
92 ; CHECK-NEXT: [[EXP:%.*]] = call i8 @llvm.sadd.sat.i8(i8 [[LHS]], i8 [[RHS]])
93 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[EXP]], 1
94 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
95 ; CHECK-NEXT: ret i1 [[R]]
99 %exp = call i8 @llvm.sadd.sat.i8(i8 %lhs, i8 %rhs)
100 %and = and i8 %exp, 1
101 %r = icmp eq i8 %and, 0
105 define i1 @sadd_sat_overflow_neg(i8 %x, i8 %y) {
106 ; CHECK-LABEL: @sadd_sat_overflow_neg(
107 ; CHECK-NEXT: ret i1 false
111 %exp = call i8 @llvm.sadd.sat.i8(i8 %lhs, i8 %rhs)
112 %r = icmp eq i8 %exp, 127
116 define i1 @ssub_sat_overflow_neg(i8 %x, i8 %y) {
117 ; CHECK-LABEL: @ssub_sat_overflow_neg(
118 ; CHECK-NEXT: ret i1 false
122 %lhs = or i8 %xx, 128
123 %rhs = or i8 %yy, 126
124 %exp = call i8 @llvm.ssub.sat.i8(i8 %lhs, i8 %rhs)
125 %r = icmp eq i8 %exp, 32
129 define i1 @ssub_sat_low_bits(i8 %x, i8 %y) {
130 ; CHECK-LABEL: @ssub_sat_low_bits(
131 ; CHECK-NEXT: ret i1 false
136 %rhs = and i8 %yy, -2
137 %exp = call i8 @llvm.ssub.sat.i8(i8 %lhs, i8 %rhs)
138 %and = and i8 %exp, 1
139 %r = icmp eq i8 %and, 0
143 define i1 @ssub_sat_fail_may_overflow(i8 %x, i8 %y) {
144 ; CHECK-LABEL: @ssub_sat_fail_may_overflow(
145 ; CHECK-NEXT: ret i1 false
150 %rhs = and i8 %yy, -2
151 %exp = call i8 @llvm.ssub.sat.i8(i8 %lhs, i8 %rhs)
152 %and = and i8 %exp, 1
153 %r = icmp eq i8 %and, 0
157 define i1 @ssub_sat_overflow_pos(i8 %x, i8 %y) {
158 ; CHECK-LABEL: @ssub_sat_overflow_pos(
159 ; CHECK-NEXT: ret i1 false
164 %rhs = or i8 %yy, 128
165 %exp = call i8 @llvm.ssub.sat.i8(i8 %lhs, i8 %rhs)
166 %r = icmp eq i8 %exp, 128