summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TypePromotion.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2022-05-21 14:02:22 -0700
committerCraig Topper <craig.topper@sifive.com>2022-05-21 14:08:15 -0700
commit4638766794b0d9e9a9262e59e3a5cccde657b2ef (patch)
tree9e1579f705e5263cc82c5f1b08eac67f36a913b3 /llvm/lib/CodeGen/TypePromotion.cpp
parent55e8f721d4d0996cbe5dc802a2c5fbe48dac0d44 (diff)
[TypePromotion] Refine fix sext/zext for promoted constant from D125294.
Reviewing the code again, I believe the sext is needed on the LHS or RHS for ICmp and only on the RHS for Add. Add an opcode check before checking the operand number. Fixes PR55627. Differential Revision: https://reviews.llvm.org/D125654
Diffstat (limited to 'llvm/lib/CodeGen/TypePromotion.cpp')
-rw-r--r--llvm/lib/CodeGen/TypePromotion.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index ea1369587609..8752a081623a 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -486,7 +486,10 @@ void IRPromoter::PromoteTree() {
if (auto *Const = dyn_cast<ConstantInt>(Op)) {
// For subtract, we don't need to sext the constant. We only put it in
// SafeWrap because SafeWrap.size() is used elsewhere.
- Constant *NewConst = (SafeWrap.contains(I) && i == 1 &&
+ // For cmp, we need to sign extend a constant appearing in either
+ // operand. For add, we should only sign extend the RHS.
+ Constant *NewConst = (SafeWrap.contains(I) &&
+ (I->getOpcode() == Instruction::ICmp || i == 1) &&
I->getOpcode() != Instruction::Sub)
? ConstantExpr::getSExt(Const, ExtTy)
: ConstantExpr::getZExt(Const, ExtTy);