Skip to content

Commit 05db347

Browse files
committed
fixup! [InstCombine] Canonicalize fcmp with inf
Address review feedbacks.
1 parent 18ab29f commit 05db347

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7771,8 +7771,10 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
77717771
const APFloat *C;
77727772
if (match(Op1, m_APFloat(C)) && C->isInfinity()) {
77737773
switch (C->isNegative() ? FCmpInst::getSwappedPredicate(Pred) : Pred) {
7774-
default:
7775-
break;
7774+
case FCmpInst::FCMP_ORD:
7775+
case FCmpInst::FCMP_UNO:
7776+
case FCmpInst::FCMP_TRUE:
7777+
case FCmpInst::FCMP_FALSE:
77767778
case FCmpInst::FCMP_OGT:
77777779
case FCmpInst::FCMP_ULE:
77787780
llvm_unreachable("Should be simplified by InstSimplify");

llvm/test/Transforms/InstCombine/canonicalize-fcmp-inf.ll

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ define i1 @oge_pinf_fmf(half %x) {
177177
ret i1 %cmp
178178
}
179179

180+
define <2 x i1> @olt_pinf_vec(<2 x half> %x) {
181+
; CHECK-LABEL: define <2 x i1> @olt_pinf_vec(
182+
; CHECK-SAME: <2 x half> [[X:%.*]]) {
183+
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <2 x half> [[X]], <half 0xH7C00, half 0xH7C00>
184+
; CHECK-NEXT: ret <2 x i1> [[CMP]]
185+
;
186+
%cmp = fcmp olt <2 x half> %x, <half 0xH7c00, half 0xH7c00>
187+
ret <2 x i1> %cmp
188+
}
189+
190+
define <2 x i1> @oge_ninf_vec(<2 x half> %x) {
191+
; CHECK-LABEL: define <2 x i1> @oge_ninf_vec(
192+
; CHECK-SAME: <2 x half> [[X:%.*]]) {
193+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ord <2 x half> [[X]], zeroinitializer
194+
; CHECK-NEXT: ret <2 x i1> [[CMP]]
195+
;
196+
%cmp = fcmp oge <2 x half> %x, <half 0xHfc00, half 0xHfc00>
197+
ret <2 x i1> %cmp
198+
}
199+
180200
; Negative tests
181201

182202
define i1 @ord_pinf(half %x) {
@@ -189,6 +209,72 @@ define i1 @ord_pinf(half %x) {
189209
ret i1 %cmp
190210
}
191211

212+
define i1 @uno_pinf(half %x) {
213+
; CHECK-LABEL: define i1 @uno_pinf(
214+
; CHECK-SAME: half [[X:%.*]]) {
215+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uno half [[X]], 0xH0000
216+
; CHECK-NEXT: ret i1 [[CMP]]
217+
;
218+
%cmp = fcmp uno half %x, 0xH7c00
219+
ret i1 %cmp
220+
}
221+
222+
define i1 @true_pinf(half %x) {
223+
; CHECK-LABEL: define i1 @true_pinf(
224+
; CHECK-SAME: half [[X:%.*]]) {
225+
; CHECK-NEXT: ret i1 true
226+
;
227+
%cmp = fcmp true half %x, 0xH7c00
228+
ret i1 %cmp
229+
}
230+
231+
define i1 @false_pinf(half %x) {
232+
; CHECK-LABEL: define i1 @false_pinf(
233+
; CHECK-SAME: half [[X:%.*]]) {
234+
; CHECK-NEXT: ret i1 false
235+
;
236+
%cmp = fcmp false half %x, 0xH7c00
237+
ret i1 %cmp
238+
}
239+
240+
define i1 @ord_ninf(half %x) {
241+
; CHECK-LABEL: define i1 @ord_ninf(
242+
; CHECK-SAME: half [[X:%.*]]) {
243+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ord half [[X]], 0xH0000
244+
; CHECK-NEXT: ret i1 [[CMP]]
245+
;
246+
%cmp = fcmp ord half %x, 0xHfc00
247+
ret i1 %cmp
248+
}
249+
250+
define i1 @uno_ninf(half %x) {
251+
; CHECK-LABEL: define i1 @uno_ninf(
252+
; CHECK-SAME: half [[X:%.*]]) {
253+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uno half [[X]], 0xH0000
254+
; CHECK-NEXT: ret i1 [[CMP]]
255+
;
256+
%cmp = fcmp uno half %x, 0xHfc00
257+
ret i1 %cmp
258+
}
259+
260+
define i1 @true_ninf(half %x) {
261+
; CHECK-LABEL: define i1 @true_ninf(
262+
; CHECK-SAME: half [[X:%.*]]) {
263+
; CHECK-NEXT: ret i1 true
264+
;
265+
%cmp = fcmp true half %x, 0xHfc00
266+
ret i1 %cmp
267+
}
268+
269+
define i1 @false_ninf(half %x) {
270+
; CHECK-LABEL: define i1 @false_ninf(
271+
; CHECK-SAME: half [[X:%.*]]) {
272+
; CHECK-NEXT: ret i1 false
273+
;
274+
%cmp = fcmp false half %x, 0xHfc00
275+
ret i1 %cmp
276+
}
277+
192278
define i1 @olt_one(half %x) {
193279
; CHECK-LABEL: define i1 @olt_one(
194280
; CHECK-SAME: half [[X:%.*]]) {

0 commit comments

Comments
 (0)