[PATCH] D137481: [TargetLowering] Do not shrink shift amount in ShrinkDemandedOp

chenglin.bi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 21:54:13 PDT 2022


bcl5980 created this revision.
bcl5980 added reviewers: RKSimon, spatel, craig.topper.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
bcl5980 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Shift amout is determined by TLI.getShiftAmountTy. We can't truncate it.


https://reviews.llvm.org/D137481

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp


Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -582,11 +582,16 @@
     EVT SmallVT = EVT::getIntegerVT(*DAG.getContext(), SmallVTBits);
     if (TLI.isTruncateFree(Op.getValueType(), SmallVT) &&
         TLI.isZExtFree(SmallVT, Op.getValueType())) {
+      SDValue RHS = Op.getOperand(1);
+      // Shift amout type is determined by TLI.getShiftAmountTy,
+      // we can't truncate here because it will cause type mismatch.
+      if (Op.getOpcode() != ISD::SHL && Op.getOpcode() != ISD::SRL &&
+          Op.getOpcode() != ISD::SRA)
+        RHS = DAG.getNode(ISD::TRUNCATE, dl, SmallVT, RHS);
       // We found a type with free casts.
       SDValue X = DAG.getNode(
           Op.getOpcode(), dl, SmallVT,
-          DAG.getNode(ISD::TRUNCATE, dl, SmallVT, Op.getOperand(0)),
-          DAG.getNode(ISD::TRUNCATE, dl, SmallVT, Op.getOperand(1)));
+          DAG.getNode(ISD::TRUNCATE, dl, SmallVT, Op.getOperand(0)), RHS);
       assert(DemandedSize <= SmallVTBits && "Narrowed below demanded bits?");
       SDValue Z = DAG.getNode(ISD::ANY_EXTEND, dl, Op.getValueType(), X);
       return TLO.CombineTo(Op, Z);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137481.473399.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221105/9b6bee25/attachment.bin>


More information about the llvm-commits mailing list