1 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14 -disable-cgp | FileCheck %s
3 ; Check that signed comparisons against 0 are eliminated if the defining
4 ; instruction is an add with immediate.
6 ; Addition of an immediate does not depend on the "nsw" flag, since the
7 ; result can be predicted in case of overflow. For example, if adding a
8 ; positive immediate gives overflow, the result must be negative.
10 ; Addition of a negative immediate gives a positive result in case of
11 ; overflow (except for the case of the minimum value which may also result in
13 define i32 @fun0(i32 %arg) {
18 %tmp = add i32 %arg, -1
19 %tmp1 = icmp eq i32 %tmp, 0
20 %res = select i1 %tmp1, i32 %tmp, i32 %arg
24 define i32 @fun1(i32 %arg) {
29 %tmp = add i32 %arg, -1
30 %tmp1 = icmp sgt i32 %tmp, 0
31 %res = select i1 %tmp1, i32 %tmp, i32 %arg
35 define i32 @fun2(i32 %arg) {
40 %tmp = add i32 %arg, -1
41 %tmp1 = icmp slt i32 %tmp, 0
42 %res = select i1 %tmp1, i32 %tmp, i32 %arg
46 ; Addition of a positive immediate gives a negative result in case of overflow.
47 define i32 @fun3(i32 %arg) {
52 %tmp = add i32 %arg, 1
53 %tmp1 = icmp eq i32 %tmp, 0
54 %res = select i1 %tmp1, i32 %tmp, i32 %arg
58 define i32 @fun4(i32 %arg) {
63 %tmp = add i32 %arg, 1
64 %tmp1 = icmp sgt i32 %tmp, 0
65 %res = select i1 %tmp1, i32 %tmp, i32 %arg
69 define i32 @fun5(i32 %arg) {
74 %tmp = add i32 %arg, 1
75 %tmp1 = icmp slt i32 %tmp, 0
76 %res = select i1 %tmp1, i32 %tmp, i32 %arg
80 ; Addition of the minimum value gives a positive or zero result.
81 define i32 @fun6(i32 %arg) {
87 %tmp = add i32 %arg, -2147483648
88 %tmp1 = icmp eq i32 %tmp, 0
89 %res = select i1 %tmp1, i32 %tmp, i32 %arg
93 define i32 @fun7(i32 %arg) {
99 %tmp = add i32 %arg, -2147483648
100 %tmp1 = icmp sgt i32 %tmp, 0
101 %res = select i1 %tmp1, i32 %tmp, i32 %arg