[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:50:11 PDT 2022
craig.topper updated this revision to Diff 429588.
craig.topper added a comment.
Add test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125654/new/
https://reviews.llvm.org/D125654
Files:
llvm/lib/CodeGen/TypePromotion.cpp
llvm/test/Transforms/TypePromotion/ARM/icmps.ll
Index: llvm/test/Transforms/TypePromotion/ARM/icmps.ll
===================================================================
--- llvm/test/Transforms/TypePromotion/ARM/icmps.ll
+++ llvm/test/Transforms/TypePromotion/ARM/icmps.ll
@@ -319,6 +319,24 @@
ret i32 %conv1
}
+define i32 @icmp_minus_imm_noncanonicalcmp(i8* %a) {
+; CHECK-LABEL: @icmp_minus_imm_noncanonicalcmp(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load i8, i8* [[A:%.*]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[TMP0]] to i32
+; CHECK-NEXT: [[ADD_I:%.*]] = add i32 [[TMP1]], -7
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 -5, [[ADD_I]]
+; CHECK-NEXT: [[CONV1:%.*]] = zext i1 [[CMP]] to i32
+; CHECK-NEXT: ret i32 [[CONV1]]
+;
+entry:
+ %0 = load i8, i8* %a, align 1
+ %add.i = add i8 %0, -7
+ %cmp = icmp ult i8 -5, %add.i
+ %conv1 = zext i1 %cmp to i32
+ ret i32 %conv1
+}
+
define void @mul_with_neg_imm(i32, i32* %b) {
; CHECK-LABEL: @mul_with_neg_imm(
; CHECK-NEXT: entry:
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.429588.patch
Type: text/x-patch
Size: 1786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/e90e795a/attachment.bin>
More information about the llvm-commits
mailing list