diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-04-26 16:04:44 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-04-26 16:04:44 +0000 |
commit | 5a90285bd98d20cd40edd776b54e13df47431485 (patch) | |
tree | a059bf33d087f12ba8c550e1d12b9794e0884b0b /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | 99a5f396d4a7d81a3f5b480c3eb682c583cb7ac6 (diff) | |
download | bcm5719-llvm-5a90285bd98d20cd40edd776b54e13df47431485.tar.gz bcm5719-llvm-5a90285bd98d20cd40edd776b54e13df47431485.zip |
[DAGCombiner] limit ftrunc optimizations with function attribute
As noted, the attribute name is subject to change once we have
the clang side implemented, but it's clear that we need some
kind of attribute-based predication here based on the discussion
for:
rL330437
llvm-svn: 330951
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index a897fb562e7..9558cb8ee00 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -10904,6 +10904,14 @@ SDValue DAGCombiner::visitFCOPYSIGN(SDNode *N) { static SDValue foldFPToIntToFP(SDNode *N, SelectionDAG &DAG, const TargetLowering &TLI) { + // This optimization is guarded by a function attribute because it may produce + // unexpected results. Ie, programs may be relying on the platform-specific + // undefined behavior when the float-to-int conversion overflows. + const Function &F = DAG.getMachineFunction().getFunction(); + Attribute CastWorkaround = F.getFnAttribute("fp-cast-overflow-workaround"); + if (CastWorkaround.getValueAsString().equals("true")) + return SDValue(); + // We only do this if the target has legal ftrunc. Otherwise, we'd likely be // replacing casts with a libcall. EVT VT = N->getValueType(0); |