Skip to content

Commit c53e2ec

Browse files
committed
Teach BasicAA that a constant expression can't alias memory provably not
allocated until runtime (such as an alloca). Patch by Hans Wennborg! llvm-svn: 88760
1 parent a9ea959 commit c53e2ec

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,12 @@ BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size,
659659
// If V1/V2 point to two different objects we know that we have no alias.
660660
if (isIdentifiedObject(O1) && isIdentifiedObject(O2))
661661
return NoAlias;
662-
662+
663+
// Constant pointers can't alias with non-const isIdentifiedObject objects.
664+
if ((isa<Constant>(O1) && isIdentifiedObject(O2) && !isa<Constant>(O2)) ||
665+
(isa<Constant>(O2) && isIdentifiedObject(O1) && !isa<Constant>(O1)))
666+
return NoAlias;
667+
663668
// Arguments can't alias with local allocations or noalias calls.
664669
if ((isa<Argument>(O1) && (isa<AllocaInst>(O2) || isNoAliasCall(O2))) ||
665670
(isa<Argument>(O2) && (isa<AllocaInst>(O1) || isNoAliasCall(O1))))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: opt %s -dse -S | FileCheck %s
2+
3+
%t = type { i32 }
4+
5+
@g = global i32 42;
6+
7+
define void @test1(%t* noalias %pp) {
8+
%p = getelementptr inbounds %t* %pp, i32 0, i32 0
9+
10+
store i32 1, i32* %p; <-- This is dead
11+
%x = load i32* inttoptr (i32 12345 to i32*)
12+
store i32 %x, i32* %p
13+
ret void
14+
; CHECK define void @test1
15+
; CHECK: store
16+
; CHECK-NOT: store
17+
; CHECK: ret void
18+
}
19+
20+
define void @test3() {
21+
store i32 1, i32* @g; <-- This is dead.
22+
store i32 42, i32* @g
23+
ret void
24+
;CHECK define void @test3
25+
;CHECK: store
26+
;CHECK-NOT: store
27+
;CHECK: ret void
28+
}
29+
30+
define void @test4(i32* %p) {
31+
store i32 1, i32* %p
32+
%x = load i32* @g; <-- %p and @g could alias
33+
store i32 %x, i32* %p
34+
ret void
35+
; CHECK define void @test4
36+
; CHECK: store
37+
; CHECK: store
38+
; CHECK: ret void
39+
}

0 commit comments

Comments
 (0)