[llvm] r348627 - [DAGCombiner] split trunc from extend in hoistLogicOpWithSameOpcodeHands; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 7 10:51:09 PST 2018
Author: spatel
Date: Fri Dec 7 10:51:08 2018
New Revision: 348627
URL: http://llvm.org/viewvc/llvm-project?rev=348627&view=rev
Log:
[DAGCombiner] split trunc from extend in hoistLogicOpWithSameOpcodeHands; NFC
This duplicates several shared checks, but we need to split
this up to fix underlying bugs in smaller steps.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=348627&r1=348626&r2=348627&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Fri Dec 7 10:51:08 2018
@@ -3729,39 +3729,54 @@ SDValue DAGCombiner::hoistLogicOpWithSam
SDValue Y = N1.getOperand(0);
EVT XVT = X.getValueType();
SDLoc DL(N);
- switch (HandOpcode) {
- case ISD::ANY_EXTEND:
- case ISD::TRUNCATE:
- case ISD::ZERO_EXTEND:
- case ISD::SIGN_EXTEND:
- // If both operands have other uses, this transform would create extra
- // instructions without eliminating anything.
- if (!N0.hasOneUse() && !N1.hasOneUse())
- return SDValue();
- // We need matching integer source types.
- // Do not hoist logic op inside of a vector extend, since it may combine
- // into a vsetcc.
- // TODO: Should the vector check apply to truncate though?
- if (VT.isVector() || XVT != Y.getValueType())
- return SDValue();
- // Don't create an illegal op during or after legalization.
- if (LegalOperations && !TLI.isOperationLegal(LogicOpcode, XVT))
- return SDValue();
- // Avoid infinite looping with PromoteIntBinOp.
- if (HandOpcode == ISD::ANY_EXTEND && LegalTypes &&
- !TLI.isTypeDesirableForOp(LogicOpcode, XVT))
- return SDValue();
- // Be extra careful sinking truncate.
- // TODO: Should we apply desirable/legal constraints to all opcodes?
- if (HandOpcode == ISD::TRUNCATE) {
- if (TLI.isZExtFree(VT, XVT) && TLI.isTruncateFree(XVT, VT))
- return SDValue();
- if (!TLI.isTypeLegal(XVT))
- return SDValue();
- }
- // logic_op (hand_op X), (hand_op Y) --> hand_op (logic_op X, Y)
- SDValue Logic = DAG.getNode(LogicOpcode, DL, XVT, X, Y);
- return DAG.getNode(HandOpcode, DL, VT, Logic);
+ if (HandOpcode == ISD::ANY_EXTEND || HandOpcode == ISD::ZERO_EXTEND ||
+ HandOpcode == ISD::SIGN_EXTEND) {
+ // If both operands have other uses, this transform would create extra
+ // instructions without eliminating anything.
+ if (!N0.hasOneUse() && !N1.hasOneUse())
+ return SDValue();
+ // We need matching integer source types.
+ // Do not hoist logic op inside of a vector extend, since it may combine
+ // into a vsetcc.
+ // TODO: Should the vector check apply to truncate though?
+ if (VT.isVector() || XVT != Y.getValueType())
+ return SDValue();
+ // Don't create an illegal op during or after legalization.
+ if (LegalOperations && !TLI.isOperationLegal(LogicOpcode, XVT))
+ return SDValue();
+ // Avoid infinite looping with PromoteIntBinOp.
+ // TODO: Should we apply desirable/legal constraints to all opcodes?
+ if (HandOpcode == ISD::ANY_EXTEND && LegalTypes &&
+ !TLI.isTypeDesirableForOp(LogicOpcode, XVT))
+ return SDValue();
+ // logic_op (hand_op X), (hand_op Y) --> hand_op (logic_op X, Y)
+ SDValue Logic = DAG.getNode(LogicOpcode, DL, XVT, X, Y);
+ return DAG.getNode(HandOpcode, DL, VT, Logic);
+ }
+
+ // logic_op (truncate x), (truncate y) --> truncate (logic_op x, y)
+ if (HandOpcode == ISD::TRUNCATE) {
+ // If both operands have other uses, this transform would create extra
+ // instructions without eliminating anything.
+ if (!N0.hasOneUse() && !N1.hasOneUse())
+ return SDValue();
+ // We need matching integer source types.
+ // Do not hoist logic op inside of a vector extend, since it may combine
+ // into a vsetcc.
+ // TODO: Should the vector check apply to truncate though?
+ if (VT.isVector() || XVT != Y.getValueType())
+ return SDValue();
+ // Don't create an illegal op during or after legalization.
+ if (LegalOperations && !TLI.isOperationLegal(LogicOpcode, XVT))
+ return SDValue();
+ // Be extra careful sinking truncate. If it's free, there's no benefit in
+ // widening a binop. Also, don't create a logic op on an illegal type.
+ if (TLI.isZExtFree(VT, XVT) && TLI.isTruncateFree(XVT, VT))
+ return SDValue();
+ if (!TLI.isTypeLegal(XVT))
+ return SDValue();
+ SDValue Logic = DAG.getNode(LogicOpcode, DL, XVT, X, Y);
+ return DAG.getNode(HandOpcode, DL, VT, Logic);
}
// For binops SHL/SRL/SRA/AND:
More information about the llvm-commits
mailing list