Skip to content

Commit 667f919

Browse files
authored
[SelectionDAG][ARM] Propagate fast math flags in visitBRCOND (#156647)
Factor out from #151275.
1 parent 5433c44 commit 667f919

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19364,13 +19364,13 @@ SDValue DAGCombiner::visitBRCOND(SDNode *N) {
1936419364
// MachineBasicBlock CFG, which is awkward.
1936519365

1936619366
// fold a brcond with a setcc condition into a BR_CC node if BR_CC is legal
19367-
// on the target.
19367+
// on the target, also copy fast math flags.
1936819368
if (N1.getOpcode() == ISD::SETCC &&
1936919369
TLI.isOperationLegalOrCustom(ISD::BR_CC,
1937019370
N1.getOperand(0).getValueType())) {
19371-
return DAG.getNode(ISD::BR_CC, SDLoc(N), MVT::Other,
19372-
Chain, N1.getOperand(2),
19373-
N1.getOperand(0), N1.getOperand(1), N2);
19371+
return DAG.getNode(ISD::BR_CC, SDLoc(N), MVT::Other, Chain,
19372+
N1.getOperand(2), N1.getOperand(0), N1.getOperand(1), N2,
19373+
N1->getFlags());
1937419374
}
1937519375

1937619376
if (N1.hasOneUse()) {

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5570,7 +5570,7 @@ static void expandf64Toi32(SDValue Op, SelectionDAG &DAG,
55705570
llvm_unreachable("Unknown VFP cmp argument!");
55715571
}
55725572

5573-
/// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some
5573+
/// OptimizeVFPBrcond - With nnan, it's legal to optimize some
55745574
/// f32 and even f64 comparisons to integer ones.
55755575
SDValue
55765576
ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const {
@@ -5712,9 +5712,12 @@ SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
57125712
return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, Chain, Dest, ARMcc, Cmp);
57135713
}
57145714

5715-
if (getTargetMachine().Options.UnsafeFPMath &&
5716-
(CC == ISD::SETEQ || CC == ISD::SETOEQ ||
5717-
CC == ISD::SETNE || CC == ISD::SETUNE)) {
5715+
SDNodeFlags Flags = Op->getFlags();
5716+
if ((getTargetMachine().Options.UnsafeFPMath || Flags.hasNoNaNs()) &&
5717+
(DAG.getDenormalMode(MVT::f32) == DenormalMode::getIEEE() &&
5718+
DAG.getDenormalMode(MVT::f64) == DenormalMode::getIEEE()) &&
5719+
(CC == ISD::SETEQ || CC == ISD::SETOEQ || CC == ISD::SETNE ||
5720+
CC == ISD::SETUNE)) {
57185721
if (SDValue Result = OptimizeVFPBrcond(Op, DAG))
57195722
return Result;
57205723
}

llvm/test/CodeGen/ARM/fpcmp-opt.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 -mattr=+vfp2 -enable-unsafe-fp-math %s -o - \
1+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 -mattr=+vfp2 %s -o - \
22
; RUN: | FileCheck %s
33

44
; rdar://7461510
@@ -42,7 +42,7 @@ entry:
4242
; CHECK-NOT: vmrs
4343
; CHECK: bne
4444
%0 = load double, ptr %a
45-
%1 = fcmp oeq double %0, 0.000000e+00
45+
%1 = fcmp nnan oeq double %0, 0.000000e+00
4646
br i1 %1, label %bb1, label %bb2
4747

4848
bb1:
@@ -65,7 +65,7 @@ entry:
6565
; CHECK-NOT: vmrs
6666
; CHECK: bne
6767
%0 = load float, ptr %a
68-
%1 = fcmp oeq float %0, 0.000000e+00
68+
%1 = fcmp nnan oeq float %0, 0.000000e+00
6969
br i1 %1, label %bb1, label %bb2
7070

7171
bb1:

0 commit comments

Comments
 (0)