summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TypePromotion.cpp
diff options
context:
space:
mode:
authorDavid Green <david.green@arm.com>2022-05-11 10:47:44 +0100
committerDavid Green <david.green@arm.com>2022-05-11 10:47:44 +0100
commit5feeceddb2b5422dcb555b6d601e35a2d7840707 (patch)
treef32d5e50afcae3043f983d624c77278333db81a8 /llvm/lib/CodeGen/TypePromotion.cpp
parentc1d48b35d88a7eb497c9f9851bfab868228c52dd (diff)
[TypePromotion] Fix sext vs zext in promoted constant
As pointed out in #55342, given non-canonical IR with multiple constants, we check the second operand in isSafeWrap, but can promote both with sext. Fix that as suggested by @craig.topper by ensuring we only extend the second constant if multiple are present. Fixes #55342 Differential Revision: https://reviews.llvm.org/D125294
Diffstat (limited to 'llvm/lib/CodeGen/TypePromotion.cpp')
-rw-r--r--llvm/lib/CodeGen/TypePromotion.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 6b991aa73de9..fa7c797c70f0 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -484,7 +484,7 @@ void IRPromoter::PromoteTree() {
continue;
if (auto *Const = dyn_cast<ConstantInt>(Op)) {
- Constant *NewConst = SafeWrap.contains(I)
+ Constant *NewConst = (SafeWrap.contains(I) && i == 1)
? ConstantExpr::getSExt(Const, ExtTy)
: ConstantExpr::getZExt(Const, ExtTy);
I->setOperand(i, NewConst);