[llvm] 5feeced - [TypePromotion] Fix sext vs zext in promoted constant
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 02:47:49 PDT 2022
Author: David Green
Date: 2022-05-11T10:47:44+01:00
New Revision: 5feeceddb2b5422dcb555b6d601e35a2d7840707
URL: https://github.com/llvm/llvm-project/commit/5feeceddb2b5422dcb555b6d601e35a2d7840707
DIFF: https://github.com/llvm/llvm-project/commit/5feeceddb2b5422dcb555b6d601e35a2d7840707.diff
LOG: [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
Added:
Modified:
llvm/lib/CodeGen/TypePromotion.cpp
llvm/test/Transforms/TypePromotion/ARM/icmps.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 6b991aa73de94..fa7c797c70f09 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);
diff --git a/llvm/test/Transforms/TypePromotion/ARM/icmps.ll b/llvm/test/Transforms/TypePromotion/ARM/icmps.ll
index 7aa1e7dbc4e5c..880ea18f43882 100644
--- a/llvm/test/Transforms/TypePromotion/ARM/icmps.ll
+++ b/llvm/test/Transforms/TypePromotion/ARM/icmps.ll
@@ -348,3 +348,16 @@ if.then:
if.end:
ret void
}
+
+define i32 @degenerateicmp() {
+; CHECK-LABEL: @degenerateicmp(
+; CHECK-NEXT: [[TMP1:%.*]] = sub i32 190, 0
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 225, [[TMP1]]
+; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 1, i32 0
+; CHECK-NEXT: ret i32 [[TMP3]]
+;
+ %1 = sub i8 -66, 0
+ %2 = icmp ugt i8 -31, %1
+ %3 = select i1 %2, i32 1, i32 0
+ ret i32 %3
+}
More information about the llvm-commits
mailing list