diff options
| author | Hal Finkel <hfinkel@anl.gov> | 2014-10-06 18:37:59 +0000 |
|---|---|---|
| committer | Hal Finkel <hfinkel@anl.gov> | 2014-10-06 18:37:59 +0000 |
| commit | 43ce71f1b13bd4325b4699f8a4573e2888168067 (patch) | |
| tree | b1167ddc48fb4a07a3f5e7301102afa942bc192a /llvm/test/Analysis/BasicAA | |
| parent | c8a821793282a5ba0dfdf0bbff3bcd25d9661238 (diff) | |
| download | bcm5719-llvm-43ce71f1b13bd4325b4699f8a4573e2888168067.tar.gz bcm5719-llvm-43ce71f1b13bd4325b4699f8a4573e2888168067.zip | |
[BasicAA] Revert "Revert r218714 - Make better use of zext and sign information."
This reverts r218944, which reverted r218714, plus a bug fix.
Description of the bug in r218714 (by Nick)
The original patch forgot to check if the Scale in VariableGEPIndex flipped the
sign of the variable. The BasicAA pass iterates over the instructions in the
order they appear in the function, and so BasicAliasAnalysis::aliasGEP is
called with the variable it first comes across as parameter GEP1. Adding a
%reorder label puts the definition of %a after %b so aliasGEP is called with %b
as the first parameter and %a as the second. aliasGEP later calculates that %a
== %b + 1 - %idxprom where %idxprom >= 0 (if %a was passed as the first
parameter it would calculate %b == %a - 1 + %idxprom where %idxprom >= 0) -
ignoring that %idxprom is scaled by -1 here lead the patch to incorrectly
conclude that %a > %b.
Revised patch by Nick White, thanks! Thanks to Lang to isolating the bug.
Slightly modified by me to add an early exit from the loop and avoid
unnecessary, but expensive, function calls.
Original commit message:
Two related things:
1. Fixes a bug when calculating the offset in GetLinearExpression. The code
previously used zext to extend the offset, so negative offsets were converted
to large positive ones.
2. Enhance aliasGEP to deduce that, if the difference between two GEP
allocations is positive and all the variables that govern the offset are also
positive (i.e. the offset is strictly after the higher base pointer), then
locations that fit in the gap between the two base pointers are NoAlias.
Patch by Nick White!
llvm-svn: 219135
Diffstat (limited to 'llvm/test/Analysis/BasicAA')
| -rw-r--r-- | llvm/test/Analysis/BasicAA/phi-aa.ll | 1 | ||||
| -rw-r--r-- | llvm/test/Analysis/BasicAA/zext.ll | 87 |
2 files changed, 88 insertions, 0 deletions
diff --git a/llvm/test/Analysis/BasicAA/phi-aa.ll b/llvm/test/Analysis/BasicAA/phi-aa.ll index 74279e1c4c9..c1100f1d36f 100644 --- a/llvm/test/Analysis/BasicAA/phi-aa.ll +++ b/llvm/test/Analysis/BasicAA/phi-aa.ll @@ -39,6 +39,7 @@ return: ; CHECK-LABEL: pr18068 ; CHECK: MayAlias: i32* %0, i32* %arrayidx5 +; CHECK: NoAlias: i32* %arrayidx13, i32* %arrayidx5 define i32 @pr18068(i32* %jj7, i32* %j) { entry: diff --git a/llvm/test/Analysis/BasicAA/zext.ll b/llvm/test/Analysis/BasicAA/zext.ll new file mode 100644 index 00000000000..33984f2474c --- /dev/null +++ b/llvm/test/Analysis/BasicAA/zext.ll @@ -0,0 +1,87 @@ +; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-LABEL: test_with_zext +; CHECK: NoAlias: i8* %a, i8* %b + +define void @test_with_zext() { + %1 = tail call i8* @malloc(i64 120) + %a = getelementptr inbounds i8* %1, i64 8 + %2 = getelementptr inbounds i8* %1, i64 16 + %3 = zext i32 3 to i64 + %b = getelementptr inbounds i8* %2, i64 %3 + ret void +} + +; CHECK-LABEL: test_with_lshr +; CHECK: NoAlias: i8* %a, i8* %b + +define void @test_with_lshr(i64 %i) { + %1 = tail call i8* @malloc(i64 120) + %a = getelementptr inbounds i8* %1, i64 8 + %2 = getelementptr inbounds i8* %1, i64 16 + %3 = lshr i64 %i, 2 + %b = getelementptr inbounds i8* %2, i64 %3 + ret void +} + +; CHECK-LABEL: test_with_a_loop +; CHECK: NoAlias: i8* %a, i8* %b + +define void @test_with_a_loop() { + %1 = tail call i8* @malloc(i64 120) + %a = getelementptr inbounds i8* %1, i64 8 + %2 = getelementptr inbounds i8* %1, i64 16 + br label %for.loop + +for.loop: + %i = phi i32 [ 0, %0 ], [ %i.next, %for.loop ] + %3 = zext i32 %i to i64 + %b = getelementptr inbounds i8* %2, i64 %3 + %i.next = add nuw nsw i32 %i, 1 + %4 = icmp eq i32 %i.next, 10 + br i1 %4, label %for.loop.exit, label %for.loop + +for.loop.exit: + ret void +} + +; CHECK-LABEL: test_sign_extension +; CHECK: PartialAlias: i64* %b.i64, i8* %a + +define void @test_sign_extension(i32 %p) { + %1 = tail call i8* @malloc(i64 120) + %p.64 = zext i32 %p to i64 + %a = getelementptr inbounds i8* %1, i64 %p.64 + %p.minus1 = add i32 %p, -1 + %p.minus1.64 = zext i32 %p.minus1 to i64 + %b.i8 = getelementptr inbounds i8* %1, i64 %p.minus1.64 + %b.i64 = bitcast i8* %b.i8 to i64* + ret void +} + +; CHECK-LABEL: test_fe_tools +; CHECK: PartialAlias: i32* %a, i32* %b + +define void @test_fe_tools([8 x i32]* %values) { + br label %reorder + +for.loop: + %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ] + %idxprom = zext i32 %i to i64 + %b = getelementptr inbounds [8 x i32]* %values, i64 0, i64 %idxprom + %i.next = add nuw nsw i32 %i, 1 + %1 = icmp eq i32 %i.next, 10 + br i1 %1, label %for.loop.exit, label %for.loop + +reorder: + %a = getelementptr inbounds [8 x i32]* %values, i64 0, i64 1 + br label %for.loop + +for.loop.exit: + ret void +} + +; Function Attrs: nounwind +declare noalias i8* @malloc(i64) |

