Skip to content

Commit 0b9b9da

Browse files
committed
Teach SelectionDAG to match more calls to libm functions onto existing SDNodes. Mark these nodes as illegal by default, unless the target declares otherwise.
llvm-svn: 146171
1 parent 4edc736 commit 0b9b9da

File tree

5 files changed

+81
-12
lines changed

5 files changed

+81
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,6 +5559,53 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
55595559
Tmp.getValueType(), Tmp));
55605560
return;
55615561
}
5562+
} else if (Name == "floor" || Name == "floorf" || Name == "floorl") {
5563+
if (I.getNumArgOperands() == 1 && // Basic sanity checks.
5564+
I.getArgOperand(0)->getType()->isFloatingPointTy() &&
5565+
I.getType() == I.getArgOperand(0)->getType()) {
5566+
SDValue Tmp = getValue(I.getArgOperand(0));
5567+
setValue(&I, DAG.getNode(ISD::FFLOOR, getCurDebugLoc(),
5568+
Tmp.getValueType(), Tmp));
5569+
return;
5570+
}
5571+
} else if (Name == "nearbyint" || Name == "nearbyintf" ||
5572+
Name == "nearbyintl") {
5573+
if (I.getNumArgOperands() == 1 && // Basic sanity checks.
5574+
I.getArgOperand(0)->getType()->isFloatingPointTy() &&
5575+
I.getType() == I.getArgOperand(0)->getType()) {
5576+
SDValue Tmp = getValue(I.getArgOperand(0));
5577+
setValue(&I, DAG.getNode(ISD::FNEARBYINT, getCurDebugLoc(),
5578+
Tmp.getValueType(), Tmp));
5579+
return;
5580+
}
5581+
} else if (Name == "ceil" || Name == "ceilf" || Name == "ceill") {
5582+
if (I.getNumArgOperands() == 1 && // Basic sanity checks.
5583+
I.getArgOperand(0)->getType()->isFloatingPointTy() &&
5584+
I.getType() == I.getArgOperand(0)->getType()) {
5585+
SDValue Tmp = getValue(I.getArgOperand(0));
5586+
setValue(&I, DAG.getNode(ISD::FCEIL, getCurDebugLoc(),
5587+
Tmp.getValueType(), Tmp));
5588+
return;
5589+
}
5590+
} else if (Name == "rint" || Name == "rintf" || Name == "rintl") {
5591+
if (I.getNumArgOperands() == 1 && // Basic sanity checks.
5592+
I.getArgOperand(0)->getType()->isFloatingPointTy() &&
5593+
I.getType() == I.getArgOperand(0)->getType()) {
5594+
SDValue Tmp = getValue(I.getArgOperand(0));
5595+
setValue(&I, DAG.getNode(ISD::FRINT, getCurDebugLoc(),
5596+
Tmp.getValueType(), Tmp));
5597+
return;
5598+
}
5599+
} else if (Name == "trunc" || Name == "truncf" || Name == "truncl") {
5600+
if (I.getNumArgOperands() == 1 && // Basic sanity checks.
5601+
I.getArgOperand(0)->getType()->isFloatingPointTy() &&
5602+
I.getType() == I.getArgOperand(0)->getType()) {
5603+
SDValue Tmp = getValue(I.getArgOperand(0));
5604+
setValue(&I, DAG.getNode(ISD::FTRUNC, getCurDebugLoc(),
5605+
Tmp.getValueType(), Tmp));
5606+
return;
5607+
}
5608+
55625609
} else if (Name == "memcmp") {
55635610
if (visitMemCmpCall(I))
55645611
return;

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +577,26 @@ TargetLowering::TargetLowering(const TargetMachine &tm,
577577
setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
578578

579579
// These library functions default to expand.
580-
setOperationAction(ISD::FLOG , MVT::f64, Expand);
581-
setOperationAction(ISD::FLOG2, MVT::f64, Expand);
582-
setOperationAction(ISD::FLOG10,MVT::f64, Expand);
583-
setOperationAction(ISD::FEXP , MVT::f64, Expand);
584-
setOperationAction(ISD::FEXP2, MVT::f64, Expand);
585-
setOperationAction(ISD::FLOG , MVT::f32, Expand);
586-
setOperationAction(ISD::FLOG2, MVT::f32, Expand);
587-
setOperationAction(ISD::FLOG10,MVT::f32, Expand);
588-
setOperationAction(ISD::FEXP , MVT::f32, Expand);
589-
setOperationAction(ISD::FEXP2, MVT::f32, Expand);
580+
setOperationAction(ISD::FLOG , MVT::f64, Expand);
581+
setOperationAction(ISD::FLOG2, MVT::f64, Expand);
582+
setOperationAction(ISD::FLOG10, MVT::f64, Expand);
583+
setOperationAction(ISD::FEXP , MVT::f64, Expand);
584+
setOperationAction(ISD::FEXP2, MVT::f64, Expand);
585+
setOperationAction(ISD::FFLOOR, MVT::f64, Expand);
586+
setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand);
587+
setOperationAction(ISD::FCEIL, MVT::f64, Expand);
588+
setOperationAction(ISD::FRINT, MVT::f64, Expand);
589+
setOperationAction(ISD::FTRUNC, MVT::f64, Expand);
590+
setOperationAction(ISD::FLOG , MVT::f32, Expand);
591+
setOperationAction(ISD::FLOG2, MVT::f32, Expand);
592+
setOperationAction(ISD::FLOG10, MVT::f32, Expand);
593+
setOperationAction(ISD::FEXP , MVT::f32, Expand);
594+
setOperationAction(ISD::FEXP2, MVT::f32, Expand);
595+
setOperationAction(ISD::FFLOOR, MVT::f32, Expand);
596+
setOperationAction(ISD::FNEARBYINT, MVT::f32, Expand);
597+
setOperationAction(ISD::FCEIL, MVT::f32, Expand);
598+
setOperationAction(ISD::FRINT, MVT::f32, Expand);
599+
setOperationAction(ISD::FTRUNC, MVT::f32, Expand);
590600

591601
// Default ISD::TRAP to expand (which turns it into abort).
592602
setOperationAction(ISD::TRAP, MVT::Other, Expand);

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
103103
// from FP_ROUND: that rounds to nearest, this rounds to zero.
104104
setOperationAction(ISD::FP_ROUND_INREG, MVT::ppcf128, Custom);
105105

106+
// We do not currently implment this libm ops for PowerPC.
107+
setOperationAction(ISD::FFLOOR, MVT::ppcf128, Expand);
108+
setOperationAction(ISD::FCEIL, MVT::ppcf128, Expand);
109+
setOperationAction(ISD::FTRUNC, MVT::ppcf128, Expand);
110+
setOperationAction(ISD::FRINT, MVT::ppcf128, Expand);
111+
setOperationAction(ISD::FNEARBYINT, MVT::ppcf128, Expand);
112+
106113
// PowerPC has no SREM/UREM instructions
107114
setOperationAction(ISD::SREM, MVT::i32, Expand);
108115
setOperationAction(ISD::UREM, MVT::i32, Expand);

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ X86TargetLowering::X86TargetLowering(X86TargetMachine &TM)
663663
setOperationAction(ISD::FCOS , MVT::f80 , Expand);
664664
}
665665

666+
setOperationAction(ISD::FFLOOR, MVT::f80, Expand);
667+
setOperationAction(ISD::FCEIL, MVT::f80, Expand);
668+
setOperationAction(ISD::FTRUNC, MVT::f80, Expand);
669+
setOperationAction(ISD::FRINT, MVT::f80, Expand);
670+
setOperationAction(ISD::FNEARBYINT, MVT::f80, Expand);
666671
setOperationAction(ISD::FMA, MVT::f80, Expand);
667672
}
668673

llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 | FileCheck %s
22
; rdar://7354379
33

4-
declare double @floor(double) nounwind readnone
4+
declare double @foo(double) nounwind readnone
55

66
define void @t(i32 %c, double %b) {
77
entry:
@@ -26,7 +26,7 @@ bb9: ; preds = %bb7
2626
; CHECK: cmp r0, #0
2727
; CHECK: cmp r0, #0
2828
; CHECK-NEXT: cbnz
29-
%0 = tail call double @floor(double %b) nounwind readnone ; <double> [#uses=0]
29+
%0 = tail call double @foo(double %b) nounwind readnone ; <double> [#uses=0]
3030
br label %bb11
3131

3232
bb11: ; preds = %bb9, %bb7

0 commit comments

Comments
 (0)