[llvm] Reduce shl64 to shl32 if shift range is [63-32] (PR #125574)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 17:36:16 PST 2025
================
@@ -4040,19 +4040,35 @@ SDValue AMDGPUTargetLowering::splitBinaryBitConstantOpImpl(
SDValue AMDGPUTargetLowering::performShlCombine(SDNode *N,
DAGCombinerInfo &DCI) const {
EVT VT = N->getValueType(0);
+ SDValue LHS = N->getOperand(0);
+ SDValue RHS = N->getOperand(1);
+ ConstantSDNode *CRHS = dyn_cast<ConstantSDNode>(RHS);
+ SDLoc SL(N);
+ SelectionDAG &DAG = DCI.DAG;
- ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N->getOperand(1));
- if (!RHS)
+ if (!CRHS) {
+ // shl i64 X, Y -> [0, shl i32 X, (Y - 32)]
+ if (VT == MVT::i64) {
+ KnownBits Known = DAG.computeKnownBits(RHS);
+ if (Known.getMinValue().getZExtValue() >= 32) {
+ SDValue truncShiftAmt = DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, RHS);
+ const SDValue C32 = DAG.getConstant(32, SL, MVT::i32);
+ SDValue ShiftAmt =
+ DAG.getNode(ISD::SUB, SL, MVT::i32, truncShiftAmt, C32);
+ SDValue Lo = DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, LHS);
+ SDValue NewShift = DAG.getNode(ISD::SHL, SL, MVT::i32, Lo, ShiftAmt);
----------------
arsenm wrote:
Can you include an alive2 link in the description? Can we preserve any flags on the shift or sub?
https://github.com/llvm/llvm-project/pull/125574
More information about the llvm-commits
mailing list