summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/min-positive.ll
blob: 82d1799f653daf455215aa2f37fcdebb05dc2848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instcombine < %s | FileCheck %s

@g = external global i32

define i1 @test(i32 %other) {
; CHECK-LABEL: @test(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 %other, 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
  %cmp = icmp slt i32 %positive, %other
  %sel = select i1 %cmp, i32 %positive, i32 %other
  %test = icmp sgt i32 %sel, 0
  ret i1 %test
}

define i1 @test2(i32 %other) {
; CHECK-LABEL: @test2(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 %other, 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
  %cmp = icmp slt i32 %other, %positive
  %sel = select i1 %cmp, i32 %other, i32 %positive
  %test = icmp sgt i32 %sel, 0
  ret i1 %test
}

; %positive might be zero
define i1 @test3(i32 %other) {
; CHECK-LABEL: @test3(
; CHECK-NEXT:    [[POSITIVE:%.*]] = load i32, i32* @g, align 4, !range !0
; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[POSITIVE]], %other
; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[POSITIVE]], i32 %other
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, i32* @g, !range !{i32 0, i32 2048}
  %cmp = icmp slt i32 %positive, %other
  %sel = select i1 %cmp, i32 %positive, i32 %other
  %test = icmp sgt i32 %sel, 0
  ret i1 %test
}
OpenPOWER on IntegriCloud