[llvm] f366acd - [DAG] Generalize (sra (trunc (sra x, c1)), c2) -> (trunc (sra x, c1 + c2)) constant folding
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 06:05:17 PDT 2022
Author: Simon Pilgrim
Date: 2022-05-26T14:05:09+01:00
New Revision: f366acdbf694f93e0d3fbaeec5a7756ea2032df2
URL: https://github.com/llvm/llvm-project/commit/f366acdbf694f93e0d3fbaeec5a7756ea2032df2
DIFF: https://github.com/llvm/llvm-project/commit/f366acdbf694f93e0d3fbaeec5a7756ea2032df2.diff
LOG: [DAG] Generalize (sra (trunc (sra x, c1)), c2) -> (trunc (sra x, c1 + c2)) constant folding
Remove local (uniform) constant folding and rely on getNode() to perform it
Minor cleanup step toward adding non-uniform shift amount support
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 2c1f7d990aad..dc2ce7f65141 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9286,8 +9286,10 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
unsigned TruncBits = LargeVT.getScalarSizeInBits() - OpSizeInBits;
if (LargeShift->getAPIntValue() == TruncBits) {
SDLoc DL(N);
- SDValue Amt = DAG.getConstant(N1C->getZExtValue() + TruncBits, DL,
- getShiftAmountTy(LargeVT));
+ EVT LargeShiftVT = getShiftAmountTy(LargeVT);
+ SDValue Amt = DAG.getZExtOrTrunc(N1, DL, LargeShiftVT);
+ Amt = DAG.getNode(ISD::ADD, DL, LargeShiftVT, Amt,
+ DAG.getConstant(TruncBits, DL, LargeShiftVT));
SDValue SRA =
DAG.getNode(ISD::SRA, DL, LargeVT, N0Op0.getOperand(0), Amt);
return DAG.getNode(ISD::TRUNCATE, DL, VT, SRA);
More information about the llvm-commits
mailing list