From fa3966881f7f0317803b09161602c9c7eeb2d3a3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 26 Nov 2009 17:00:01 +0000 Subject: [PATCH] teach GetLinearExpression to be a bit more aggressive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89955 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicAliasAnalysis.cpp | 11 ++++++++++- test/Analysis/BasicAA/gep-alias.ll | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index c038b207058..e10e1f2d4ce 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -400,7 +400,16 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset, V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD); Offset += RHSC->getValue(); return V; - // TODO: SHL, MUL. + case Instruction::Mul: + V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD); + Offset *= RHSC->getValue(); + Scale *= RHSC->getValue(); + return V; + case Instruction::Shl: + V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD); + Offset <<= RHSC->getValue().getLimitedValue(); + Scale <<= RHSC->getValue().getLimitedValue(); + return V; } } } diff --git a/test/Analysis/BasicAA/gep-alias.ll b/test/Analysis/BasicAA/gep-alias.ll index 320c9907d53..68722fbfd0e 100644 --- a/test/Analysis/BasicAA/gep-alias.ll +++ b/test/Analysis/BasicAA/gep-alias.ll @@ -101,3 +101,18 @@ define i32 @test6(i32* %p, i64 %i1) { ; CHECK: ret i32 0 } +; P[1] != P[i*4] +define i32 @test7(i32* %p, i64 %i) { + %pi = getelementptr i32* %p, i64 1 + %i.next = shl i64 %i, 2 + %pi.next = getelementptr i32* %p, i64 %i.next + %x = load i32* %pi + store i32 42, i32* %pi.next + %y = load i32* %pi + %z = sub i32 %x, %y + ret i32 %z +; CHECK: @test7 +; CHECK: ret i32 0 +} + +