Skip to content
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

[BasicAA] Remove NSW flags when merging scales #69122

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Oct 15, 2023

When merging scales of LinearExpression that have common index variables, we cannot guarantee the NSW flag still applies to the merged expression.

Fixes #69096.

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 15, 2023

@llvm/pr-subscribers-llvm-analysis

Author: Yingwei Zheng (dtcxzyw)

Changes

When merging scales of LinearExpression that have common index variables, we cannot guarantee the NSW flag still applies to the merged expression.

Fixes #69096.


Full diff: https://github.com/llvm/llvm-project/pull/69122.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+1)
  • (modified) llvm/test/Analysis/BasicAA/pr69096.ll (+2-2)
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index c162b8f6edc1905..ca65abeb591c561 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -662,6 +662,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
         if (Decomposed.VarIndices[i].Val.V == LE.Val.V &&
             Decomposed.VarIndices[i].Val.hasSameCastsAs(LE.Val)) {
           Scale += Decomposed.VarIndices[i].Scale;
+          LE.IsNSW = false; // We cannot guarantee nsw for the merge.
           Decomposed.VarIndices.erase(Decomposed.VarIndices.begin() + i);
           break;
         }
diff --git a/llvm/test/Analysis/BasicAA/pr69096.ll b/llvm/test/Analysis/BasicAA/pr69096.ll
index 7d8506b81c2bfbf..fe8504a0308ad71 100644
--- a/llvm/test/Analysis/BasicAA/pr69096.ll
+++ b/llvm/test/Analysis/BasicAA/pr69096.ll
@@ -3,8 +3,8 @@
 target datalayout = "p:64:64:64"
 
 ; CHECK-LABEL: Function: pr69096
-; FIXME: This should be MayAlias. %p == %scevgep.i when %a == -1.
-; CHECK: NoAlias:     i8* %p, i16* %scevgep.i
+; %p == %scevgep.i when %a == -1.
+; CHECK: MayAlias:     i8* %p, i16* %scevgep.i
 
 define i32 @pr69096(i16 %a, ptr %p) {
 entry:

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dtcxzyw dtcxzyw merged commit ea4cc20 into llvm:main Oct 15, 2023
4 checks passed
@dtcxzyw dtcxzyw deleted the fix-basic-aa-nsw branch October 15, 2023 20:40
@fhahn
Copy link
Contributor

fhahn commented Oct 16, 2023

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong code at -O2/3/s on x86_64-linux_gnu since 45ecfed
4 participants