1; RUN: opt -S -instcombine < %s | FileCheck %s
2
3@g = external global i32
4
5define i1 @test(i32 %other) {
6; CHECK-LABEL: @test
7; CHECK: %test = icmp sgt i32 %other, 0
8  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
9  %cmp = icmp slt i32 %positive, %other
10  %sel = select i1 %cmp, i32 %positive, i32 %other
11  %test = icmp sgt i32 %sel, 0
12  ret i1 %test
13}
14
15define i1 @test2(i32 %other) {
16; CHECK-LABEL: @test2
17; CHECK: %test = icmp sgt i32 %other, 0
18  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
19  %cmp = icmp slt i32 %other, %positive
20  %sel = select i1 %cmp, i32 %other, i32 %positive
21  %test = icmp sgt i32 %sel, 0
22  ret i1 %test
23}
24
25; %positive might be zero
26define i1 @test3(i32 %other) {
27; CHECK-LABEL: @test3
28; CHECK: %test = icmp sgt i32 %sel, 0
29  %positive = load i32, i32* @g, !range !{i32 0, i32 2048}
30  %cmp = icmp slt i32 %positive, %other
31  %sel = select i1 %cmp, i32 %positive, i32 %other
32  %test = icmp sgt i32 %sel, 0
33  ret i1 %test
34}
35