[llvm-commits] [llvm] r63207 - in /llvm/branches/release_25/lib/CodeGen/SelectionDAG: DAGCombiner.cpp SelectionDAG.cpp
Tanya Lattner
tonic at nondot.org
Wed Jan 28 07:43:23 PST 2009
Author: tbrethou
Date: Wed Jan 28 09:43:23 2009
New Revision: 63207
URL: http://llvm.org/viewvc/llvm-project?rev=63207&view=rev
Log:
Merge from mainline.
Fold x-0 to x in unsafe-fp-math mode. This comes up in the
testcase from PR3376, and in fact is sufficient to completely
avoid the problem in that testcase.
There's an underlying problem though; TLI.isOperationLegal
considers Custom to be Legal, which might be ok in some
cases, but that's what DAGCombiner is using in many places
to test if something is legal when LegalOperations is true.
When DAGCombiner is running after legalize, this isn't
sufficient. I'll address this in a separate commit.
Modified:
llvm/branches/release_25/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/branches/release_25/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/branches/release_25/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=63207&r1=63206&r2=63207&view=diff
==============================================================================
--- llvm/branches/release_25/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/branches/release_25/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Jan 28 09:43:23 2009
@@ -3851,6 +3851,9 @@
// fold (fsub c1, c2) -> c1-c2
if (N0CFP && N1CFP && VT != MVT::ppcf128)
return DAG.getNode(ISD::FSUB, VT, N0, N1);
+ // fold (A-0) -> A
+ if (UnsafeFPMath && N1CFP && N1CFP->getValueAPF().isZero())
+ return N0;
// fold (0-B) -> -B
if (UnsafeFPMath && N0CFP && N0CFP->getValueAPF().isZero()) {
if (isNegatibleForFree(N1, LegalOperations))
Modified: llvm/branches/release_25/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=63207&r1=63206&r2=63207&view=diff
==============================================================================
--- llvm/branches/release_25/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/branches/release_25/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Jan 28 09:43:23 2009
@@ -2387,15 +2387,22 @@
case ISD::FMUL:
case ISD::FDIV:
case ISD::FREM:
- if (UnsafeFPMath && Opcode == ISD::FADD) {
- // 0+x --> x
- if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1))
- if (CFP->getValueAPF().isZero())
- return N2;
- // x+0 --> x
- if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N2))
- if (CFP->getValueAPF().isZero())
- return N1;
+ if (UnsafeFPMath) {
+ if (Opcode == ISD::FADD) {
+ // 0+x --> x
+ if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1))
+ if (CFP->getValueAPF().isZero())
+ return N2;
+ // x+0 --> x
+ if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N2))
+ if (CFP->getValueAPF().isZero())
+ return N1;
+ } else if (Opcode == ISD::FSUB) {
+ // x-0 --> x
+ if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N2))
+ if (CFP->getValueAPF().isZero())
+ return N1;
+ }
}
assert(N1.getValueType() == N2.getValueType() &&
N1.getValueType() == VT && "Binary operator types must match!");
More information about the llvm-commits
mailing list