Skip to content

Commit 09fd267

Browse files
committed
[InstCombine] Add additional tests. NFC.
1 parent d17041a commit 09fd267

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

llvm/test/Transforms/InstCombine/fcmp-select.ll

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
33

44
declare void @use(i1)
5+
declare void @usef64(double)
56

67
; X == 42.0 ? X : 42.0 --> 42.0
78

@@ -176,9 +177,9 @@ define i1 @test_fcmp_select_var_const(double %x, double %y) {
176177
define i1 @test_fcmp_select_var_const_fmf(double %x, double %y) {
177178
; CHECK-LABEL: @test_fcmp_select_var_const_fmf(
178179
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ule double [[X:%.*]], 0x3E80000000000000
179-
; CHECK-NEXT: [[CMP2:%.*]] = fcmp nnan olt double [[SEL:%.*]], 0x3E80000000000000
180-
; CHECK-NEXT: [[CMP3:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]]
181-
; CHECK-NEXT: ret i1 [[CMP3]]
180+
; CHECK-NEXT: [[TMP1:%.*]] = fcmp nnan olt double [[Y:%.*]], 0x3E80000000000000
181+
; CHECK-NEXT: [[CMP2:%.*]] = select i1 [[CMP1]], i1 true, i1 [[TMP1]]
182+
; CHECK-NEXT: ret i1 [[CMP2]]
182183
;
183184
%cmp1 = fcmp ogt double %x, 0x3E80000000000000
184185
%sel = select i1 %cmp1, double %y, double 0.000000e+00
@@ -213,3 +214,33 @@ define double @test_fcmp_select_clamp(double %x) {
213214
%sel2 = select i1 %cmp2, double 5.000000e-01, double %sel1
214215
ret double %sel2
215216
}
217+
218+
; Don't break fmin/fmax idioms
219+
220+
define double @test_fcmp_select_maxnum(double %x) {
221+
; CHECK-LABEL: @test_fcmp_select_maxnum(
222+
; CHECK-NEXT: [[SEL1:%.*]] = call nnan nsz double @llvm.maxnum.f64(double [[X:%.*]], double 1.000000e+00)
223+
; CHECK-NEXT: [[SEL2:%.*]] = call nnan nsz double @llvm.minnum.f64(double [[SEL1]], double 2.550000e+02)
224+
; CHECK-NEXT: ret double [[SEL2]]
225+
;
226+
%cmp1 = fcmp ogt double %x, 1.0
227+
%sel1 = select nnan nsz i1 %cmp1, double %x, double 1.0
228+
%cmp2 = fcmp olt double %sel1, 255.0
229+
%sel2 = select nnan nsz i1 %cmp2, double %sel1, double 255.0
230+
ret double %sel2
231+
}
232+
233+
define i1 @test_fcmp_select_const_const_multiuse(double %x) {
234+
; CHECK-LABEL: @test_fcmp_select_const_const_multiuse(
235+
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord double [[X:%.*]], 0.000000e+00
236+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP1]], double 0xFFFFFFFFFFFFFFFF, double 0.000000e+00
237+
; CHECK-NEXT: call void @usef64(double [[SEL]])
238+
; CHECK-NEXT: [[CMP2:%.*]] = fcmp oeq double [[SEL]], 0.000000e+00
239+
; CHECK-NEXT: ret i1 [[CMP2]]
240+
;
241+
%cmp1 = fcmp ord double %x, 0.000000e+00
242+
%sel = select i1 %cmp1, double 0xFFFFFFFFFFFFFFFF, double 0.000000e+00
243+
call void @usef64(double %sel)
244+
%cmp2 = fcmp oeq double %sel, 0.000000e+00
245+
ret i1 %cmp2
246+
}

0 commit comments

Comments
 (0)