[PATCH] D125654: [TypePromotion] Refine fix sext/zext for promoted constant from D125294.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 15 18:31:49 PDT 2022


craig.topper created this revision.
craig.topper added reviewers: dmgreen, samparker.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.

Reviewing the code again, I believe the sext is needed on the LHS
or RHS for ICmp and only on the RHS for Add/Sub.

Add an opcode check before checking the operand number.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125654

Files:
  llvm/lib/CodeGen/TypePromotion.cpp


Index: llvm/lib/CodeGen/TypePromotion.cpp
===================================================================
--- llvm/lib/CodeGen/TypePromotion.cpp
+++ llvm/lib/CodeGen/TypePromotion.cpp
@@ -484,7 +484,10 @@
         continue;
 
       if (auto *Const = dyn_cast<ConstantInt>(Op)) {
-        Constant *NewConst = (SafeWrap.contains(I) && i == 1)
+        // For ICmp, the constant can be on the LHS or RHS. For Add/Sub the
+        // constant we checked for sext is on the RHS.
+        Constant *NewConst = (SafeWrap.contains(I) &&
+                              (I->getOpcode() == Instruction::ICmp || i == 1))
                                  ? ConstantExpr::getSExt(Const, ExtTy)
                                  : ConstantExpr::getZExt(Const, ExtTy);
         I->setOperand(i, NewConst);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125654.429586.patch
Type: text/x-patch
Size: 797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/cc976ede/attachment.bin>


More information about the llvm-commits mailing list