[llvm] 237b962 - [BasicAA] Account for cycles when checking for same select condition
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 01:38:01 PDT 2022
Author: Nikita Popov
Date: 2022-10-14T10:37:40+02:00
New Revision: 237b96203141aa12fa891c1b1506173d851aa07f
URL: https://github.com/llvm/llvm-project/commit/237b96203141aa12fa891c1b1506173d851aa07f
DIFF: https://github.com/llvm/llvm-project/commit/237b96203141aa12fa891c1b1506173d851aa07f.diff
LOG: [BasicAA] Account for cycles when checking for same select condition
If we have translated across a cycle backedge, the same SSA value
for the condition might be referring to two different loop iterations.
Use the isValueEqualInPotentialCycles() helper to avoid assuming
equality in that case.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/phi-and-select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 16d5f39c31cd2..9ec34fa511460 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1303,7 +1303,8 @@ BasicAAResult::aliasSelect(const SelectInst *SI, LocationSize SISize,
// If the values are Selects with the same condition, we can do a more precise
// check: just check for aliases between the values on corresponding arms.
if (const SelectInst *SI2 = dyn_cast<SelectInst>(V2))
- if (SI->getCondition() == SI2->getCondition()) {
+ if (isValueEqualInPotentialCycles(SI->getCondition(),
+ SI2->getCondition())) {
AliasResult Alias =
AAQI.AAR.alias(MemoryLocation(SI->getTrueValue(), SISize),
MemoryLocation(SI2->getTrueValue(), V2Size), AAQI);
diff --git a/llvm/test/Analysis/BasicAA/phi-and-select.ll b/llvm/test/Analysis/BasicAA/phi-and-select.ll
index e7614bbd10585..8b5352b25ac7b 100644
--- a/llvm/test/Analysis/BasicAA/phi-and-select.ll
+++ b/llvm/test/Analysis/BasicAA/phi-and-select.ll
@@ -82,10 +82,9 @@ entry:
; On the first iteration, sel1 = a1, sel2 = a2, phi = a3
; On the second iteration, sel1 = a2, sel1 = a1, phi = a2
; As such, sel1 and phi may alias.
-; FIXME: Miscompile.
; CHECK-LABEL: Function: select_backedge
; CHECK: NoAlias: i32* %sel1, i32* %sel2
-; CHECK: NoAlias: i32* %phi, i32* %sel1
+; CHECK: MayAlias: i32* %phi, i32* %sel1
; CHECK: MayAlias: i32* %phi, i32* %sel2
define void @select_backedge() {
entry:
More information about the llvm-commits
mailing list