[llvm] [BasicAA] Remove NSW flags when merging scales (PR #69122)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 15 12:49:39 PDT 2023
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/69122
When merging scales of `LinearExpression` that have common index variables, we cannot guarantee the NSW flag still applies to the merged expression.
Fixes #69096.
>From a52660a3351880f70385e461c5cd5a7fc99835dd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 16 Oct 2023 03:35:16 +0800
Subject: [PATCH] [BasicAA] Remove NSW flags when merging scales
---
llvm/lib/Analysis/BasicAliasAnalysis.cpp | 1 +
llvm/test/Analysis/BasicAA/pr69096.ll | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
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:
More information about the llvm-commits
mailing list