Skip to content

Commit e15465d

Browse files
committed
[SCEVAA] Try to handle two inttoptrs with different pointer bases
1 parent de57983 commit e15465d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ AliasResult SCEVAAResult::alias(const MemoryLocation &LocA,
6161
? static_cast<uint64_t>(LocB.Size.getValue())
6262
: MemoryLocation::UnknownSize);
6363

64+
// Before calling getMinusSCEV(), we could try the ptrtpoint pointer
65+
// operands so that you can handle two pointers with different pointer
66+
// bases.
67+
const SCEV *AInt =
68+
SE.getPtrToIntExpr(AS, SE.getEffectiveSCEVType(AS->getType()));
69+
if (!isa<SCEVCouldNotCompute>(AInt))
70+
AS = AInt;
71+
const SCEV *BInt =
72+
SE.getPtrToIntExpr(BS, SE.getEffectiveSCEVType(BS->getType()));
73+
if (!isa<SCEVCouldNotCompute>(BInt))
74+
BS = BInt;
75+
6476
// Compute the difference between the two pointers.
6577
const SCEV *BA = SE.getMinusSCEV(BS, AS);
6678

llvm/test/Analysis/ScalarEvolution/scev-aa.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,29 @@ for.latch:
340340
for.end:
341341
ret void
342342
}
343+
344+
; CHECK-LABEL: Function: test_different_pointer_bases_of_inttoptr: 2 pointers, 0 call sites
345+
; CHECK: NoAlias: <16 x i8>* %tmp5, <16 x i8>* %tmp7
346+
347+
define void @test_different_pointer_bases_of_inttoptr() {
348+
entry:
349+
br label %for.body
350+
351+
for.body:
352+
%tmp = phi i32 [ %next, %for.body ], [ 1, %entry ]
353+
%tmp1 = shl nsw i32 %tmp, 1
354+
%tmp2 = add nuw nsw i32 %tmp1, %tmp1
355+
%tmp3 = mul nsw i32 %tmp2, 1408
356+
%tmp4 = add nsw i32 %tmp3, 1408
357+
%tmp5 = getelementptr inbounds i8, ptr inttoptr (i32 1024 to ptr), i32 %tmp1
358+
%tmp6 = load <16 x i8>, ptr %tmp5, align 1
359+
%tmp7 = getelementptr inbounds i8, ptr inttoptr (i32 4096 to ptr), i32 %tmp4
360+
store <16 x i8> %tmp6, ptr %tmp7, align 1
361+
362+
%next = add i32 %tmp, 2
363+
%exitcond = icmp slt i32 %next, 10
364+
br i1 %exitcond, label %for.body, label %for.end
365+
366+
for.end:
367+
ret void
368+
}

0 commit comments

Comments
 (0)