File: min-positive.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (111 lines) | stat: -rw-r--r-- 4,087 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=instcombine < %s | FileCheck %s

@g = external global i32

define i1 @smin(i32 %other) {
; CHECK-LABEL: @smin(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, ptr @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 @smin_int(i32 %other) {
; CHECK-LABEL: @smin_int(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, ptr @g, !range !{i32 1, i32 2048}
  %smin = call i32 @llvm.smin.i32(i32 %positive, i32 %other)
  %test = icmp sgt i32 %smin, 0
  ret i1 %test
}
declare i32 @llvm.smin.i32(i32, i32)

; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().

define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {
; CHECK-LABEL: @smin_vec(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
; CHECK-NEXT:    ret <2 x i1> [[TEST]]
;
  %notneg = and <2 x i32> %x, <i32 7, i32 7>
  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
  %cmp = icmp slt <2 x i32> %positive, %other
  %sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other
  %test = icmp sgt <2 x i32> %sel, zeroinitializer
  ret <2 x i1> %test
}

define i1 @smin_commute(i32 %other) {
; CHECK-LABEL: @smin_commute(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, ptr @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
}

define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {
; CHECK-LABEL: @smin_commute_vec(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer
; CHECK-NEXT:    ret <2 x i1> [[TEST]]
;
  %notneg = and <2 x i32> %x, <i32 7, i32 7>
  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
  %cmp = icmp slt <2 x i32> %other, %positive
  %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
  %test = icmp sgt <2 x i32> %sel, zeroinitializer
  ret <2 x i1> %test
}

define <2 x i1> @smin_commute_vec_undef_elts(<2 x i32> %x, <2 x i32> %other) {
; CHECK-LABEL: @smin_commute_vec_undef_elts(
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], <i32 0, i32 undef>
; CHECK-NEXT:    ret <2 x i1> [[TEST]]
;
  %notneg = and <2 x i32> %x, <i32 7, i32 7>
  %positive = or <2 x i32> %notneg, <i32 1, i32 1>
  %cmp = icmp slt <2 x i32> %other, %positive
  %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive
  %test = icmp sgt <2 x i32> %sel, <i32 0, i32 undef>
  ret <2 x i1> %test
}
; %positive might be zero

define i1 @maybe_not_positive(i32 %other) {
; CHECK-LABEL: @maybe_not_positive(
; CHECK-NEXT:    [[POSITIVE:%.*]] = load i32, ptr @g, align 4, !range [[RNG0:![0-9]+]]
; CHECK-NEXT:    [[SEL:%.*]] = call i32 @llvm.smin.i32(i32 [[POSITIVE]], i32 [[OTHER:%.*]])
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt i32 [[SEL]], 0
; CHECK-NEXT:    ret i1 [[TEST]]
;
  %positive = load i32, ptr @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
}

define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {
; CHECK-LABEL: @maybe_not_positive_vec(
; CHECK-NEXT:    [[NOTNEG:%.*]] = and <2 x i32> [[X:%.*]], <i32 7, i32 7>
; CHECK-NEXT:    [[SEL:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[NOTNEG]], <2 x i32> [[OTHER:%.*]])
; CHECK-NEXT:    [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer
; CHECK-NEXT:    ret <2 x i1> [[TEST]]
;
  %notneg = and <2 x i32> %x, <i32 7, i32 7>
  %cmp = icmp slt <2 x i32> %notneg, %other
  %sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other
  %test = icmp sgt <2 x i32> %sel, zeroinitializer
  ret <2 x i1> %test
}