-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGenPrepare] Replace deleted ext instr with the promoted value. #71058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-x86 Author: Yingwei Zheng (dtcxzyw) ChangesThis PR replaces the deleted sext with the promoted value in Full diff: https://github.com/llvm/llvm-project/pull/71058.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 187820717b6fd5c..9018b87835b775f 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2634,6 +2634,15 @@ struct ExtAddrMode : public TargetLowering::AddrMode {
void print(raw_ostream &OS) const;
void dump() const;
+ void replaceWith(Value *From, Value *To) {
+ if (BaseReg == From)
+ BaseReg = To;
+ if (ScaledReg == From)
+ ScaledReg = To;
+ if (OriginalValue == From)
+ OriginalValue = To;
+ }
+
FieldName compare(const ExtAddrMode &other) {
// First check that the types are the same on each field, as differing types
// is something we can't cope with later on.
@@ -4933,6 +4942,9 @@ bool AddressingModeMatcher::matchOperationAddr(User *AddrInst, unsigned Opcode,
TPT.rollback(LastKnownGood);
return false;
}
+
+ // SExt has been deleted. Make sure it is not referenced by the AddrMode.
+ AddrMode.replaceWith(Ext, PromotedOperand);
return true;
}
}
diff --git a/llvm/test/CodeGen/X86/codegen-prepare-addrmode-sext.ll b/llvm/test/CodeGen/X86/codegen-prepare-addrmode-sext.ll
index 6e95c91e7398932..a7f6f803d58fd4c 100644
--- a/llvm/test/CodeGen/X86/codegen-prepare-addrmode-sext.ll
+++ b/llvm/test/CodeGen/X86/codegen-prepare-addrmode-sext.ll
@@ -507,3 +507,25 @@ define i8 @oneArgPromotionBlockSExtZExt(i1 %arg1, ptr %base) {
%res = load i8, ptr %arrayidx
ret i8 %res
}
+
+; Check that we replace the deleted sext with the promoted value.
+; CHECK-LABEL: define void @pr70938(
+; CHECK-SAME: ptr [[F:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 0, 0
+; CHECK-NEXT: [[SUNKADDR:%.*]] = mul i64 [[ADD]], 2
+; CHECK-NEXT: [[SUNKADDR1:%.*]] = getelementptr i8, ptr [[F]], i64 [[SUNKADDR]]
+; CHECK-NEXT: store i8 0, ptr [[SUNKADDR1]], align 1
+; CHECK-NEXT: ret void
+define void @pr70938(ptr %f) {
+entry:
+ %add = add nsw i32 0, 0
+ %idxprom3 = sext i32 %add to i64
+ %arrayidx4 = getelementptr [2 x [1 x [2 x i8]]], ptr %f, i64 0, i64 %idxprom3
+ %arrayidx8 = getelementptr [2 x i8], ptr %arrayidx4, i64 0, i64 %idxprom3
+ br label %if.end
+
+if.end: ; preds = %entry
+ store i8 0, ptr %arrayidx8, align 1
+ ret void
+}
|
llvm/lib/CodeGen/CodeGenPrepare.cpp
Outdated
@@ -2634,6 +2634,15 @@ struct ExtAddrMode : public TargetLowering::AddrMode { | |||
void print(raw_ostream &OS) const; | |||
void dump() const; | |||
|
|||
void replaceWith(Value *From, Value *To) { | |||
if (BaseReg == From) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all cases below covered by the one new test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I have no idea how to generate tests that would cover all these branches :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do any of the duplicates provide a test case for the other cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two test cases only cover if (ScaledReg == From) ScaledReg = To;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we only keep the second case since existing tests do not cover other cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable.
Ping. |
Can you say at which point the sext is assigned to which member of the AddrMode and at which point it is later used again? Also, does this have any relation to what the MovedAway flag is trying to handle? |
Needs rebase? Is this still relevant? |
8479b9d
to
e687f82
Compare
✅ With the latest revision this PR passed the undef deprecator. |
For the second case, the zext is assigned to llvm-project/llvm/lib/CodeGen/CodeGenPrepare.cpp Line 4527 in bfa711a
After deleting the zext, it is used by llvm-project/llvm/lib/CodeGen/CodeGenPrepare.cpp Lines 5966 to 5978 in bfa711a
|
e687f82
to
9579db1
Compare
…mode-sext.ll` (#122101) Needed by llvm/llvm-project#71058
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…value. Add comments for `replaceWith`.
9579db1
to
f4be2b6
Compare
/cherry-pick 3c6aa04 |
/pull-request #125040 |
…lvm#71058) This PR replaces the deleted ext with the promoted value in `AddrMode`. Fixes llvm#70938. (cherry picked from commit 3c6aa04)
This PR replaces the deleted ext with the promoted value in
AddrMode
.Fixes #70938.