comparison test/Transforms/InstCombine/min-positive.ll @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents
children c2174574ed3a
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
3
4 @g = external global i32
5
6 define i1 @smin(i32 %other) {
7 ; CHECK-LABEL: @smin(
8 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 %other, 0
9 ; CHECK-NEXT: ret i1 [[TEST]]
10 ;
11 %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
12 %cmp = icmp slt i32 %positive, %other
13 %sel = select i1 %cmp, i32 %positive, i32 %other
14 %test = icmp sgt i32 %sel, 0
15 ret i1 %test
16 }
17
18 ; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().
19
20 define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {
21 ; CHECK-LABEL: @smin_vec(
22 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> %other, zeroinitializer
23 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
24 ;
25 %notneg = and <2 x i32> %x, <i32 7, i32 7>
26 %positive = or <2 x i32> %notneg, <i32 1, i32 1>
27 %cmp = icmp slt <2 x i32> %positive, %other
28 %sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other
29 %test = icmp sgt <2 x i32> %sel, zeroinitializer
30 ret <2 x i1> %test
31 }
32
33 define i1 @smin_commute(i32 %other) {
34 ; CHECK-LABEL: @smin_commute(
35 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 %other, 0
36 ; CHECK-NEXT: ret i1 [[TEST]]
37 ;
38 %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
39 %cmp = icmp slt i32 %other, %positive
40 %sel = select i1 %cmp, i32 %other, i32 %positive
41 %test = icmp sgt i32 %sel, 0
42 ret i1 %test
43 }
44
45 define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {
46 ; CHECK-LABEL: @smin_commute_vec(
47 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> %other, zeroinitializer
48 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
49 ;
50 %notneg = and <2 x i32> %x, <i32 7, i32 7>
51 %positive = or <2 x i32> %notneg, <i32 1, i32 1>
52 %cmp = icmp slt <2 x i32> %other, %positive
53 %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
54 %test = icmp sgt <2 x i32> %sel, zeroinitializer
55 ret <2 x i1> %test
56 }
57
58 ; %positive might be zero
59
60 define i1 @maybe_not_positive(i32 %other) {
61 ; CHECK-LABEL: @maybe_not_positive(
62 ; CHECK-NEXT: [[POSITIVE:%.*]] = load i32, i32* @g, align 4, !range !0
63 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[POSITIVE]], %other
64 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[POSITIVE]], i32 %other
65 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
66 ; CHECK-NEXT: ret i1 [[TEST]]
67 ;
68 %positive = load i32, i32* @g, !range !{i32 0, i32 2048}
69 %cmp = icmp slt i32 %positive, %other
70 %sel = select i1 %cmp, i32 %positive, i32 %other
71 %test = icmp sgt i32 %sel, 0
72 ret i1 %test
73 }
74
75 define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {
76 ; CHECK-LABEL: @maybe_not_positive_vec(
77 ; CHECK-NEXT: [[NOTNEG:%.*]] = and <2 x i32> %x, <i32 7, i32 7>
78 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[NOTNEG]], %other
79 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NOTNEG]], <2 x i32> %other
80 ; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer
81 ; CHECK-NEXT: ret <2 x i1> [[TEST]]
82 ;
83 %notneg = and <2 x i32> %x, <i32 7, i32 7>
84 %cmp = icmp slt <2 x i32> %notneg, %other
85 %sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other
86 %test = icmp sgt <2 x i32> %sel, zeroinitializer
87 ret <2 x i1> %test
88 }
89