[llvm] [DAGCombine] Propagate truncate to operands (PR #98666)
Justin Fargnoli via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 11:00:23 PDT 2024
================
@@ -15198,6 +15202,25 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
break;
}
+ if (TLI.shouldReduceRegisterPressure()) {
+ switch (N0.getOpcode()) {
+ case ISD::ADD:
+ case ISD::SUB:
+ case ISD::MUL:
+ case ISD::AND:
+ case ISD::OR:
+ case ISD::XOR:
+ if (!(N0.hasOneUse() && VT.isScalarInteger() &&
+ TLI.isTruncateFree(SrcVT, VT)))
+ break;
+ if (LegalOperations && !TLI.isOperationLegal(N0.getOpcode(), VT))
+ break;
+ SDValue NarrowL = DAG.getNode(ISD::TRUNCATE, DL, VT, N0.getOperand(0));
+ SDValue NarrowR = DAG.getNode(ISD::TRUNCATE, DL, VT, N0.getOperand(1));
+ return DAG.getNode(N0.getOpcode(), DL, VT, NarrowL, NarrowR);
+ }
+ }
----------------
justinfargnoli wrote:
The `switch` above looks for ["a suitable binary operation with a non-opaque constant operand,"](https://github.com/llvm/llvm-project/blob/7b801c19a0ac21b07883ee58ba550865a4e25075/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L15150) whereas this `switch` will run regardless of whether an operand is constant.
Originally, I tried to extend the existing `switch`, but this approach felt cleaner.
https://github.com/llvm/llvm-project/pull/98666
More information about the llvm-commits
mailing list