llvm.org GIT mirror llvm / e513820
[BasicAA] Fix - missed alias in GEP expressions In BasicAA GEP operand values get adjusted ("wrap-around") based on the pointersize. Otherwise, in non-64b modes, AA could report false negatives. However, a wrap-around is valid only for a fully evaluated expression. It had been introduced to fix an alias problem in http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160118/326163.html. This commit restricts the wrap-around to constant gep operands only where the value is known at compile-time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284908 91177308-0d34-0410-b5e6-96231b3b80d8 Gerolf Hoflehner 3 years ago
2 changed file(s) with 54 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
408408 // Walk the indices of the GEP, accumulating them into BaseOff/VarIndices.
409409 gep_type_iterator GTI = gep_type_begin(GEPOp);
410410 unsigned PointerSize = DL.getPointerSizeInBits(AS);
411 // Assume all GEP operands are constants until proven otherwise.
412 bool GepHasConstantOffset = true;
411413 for (User::const_op_iterator I = GEPOp->op_begin() + 1, E = GEPOp->op_end();
412414 I != E; ++I) {
413415 const Value *Index = *I;
432434 continue;
433435 }
434436
437 GepHasConstantOffset = false;
438
435439 uint64_t Scale = DL.getTypeAllocSize(*GTI);
436440 unsigned ZExtBits = 0, SExtBits = 0;
437441
457461 // A[x][x] -> x*16 + x*4 -> x*20
458462 // This also ensures that 'x' only appears in the index list once.
459463 for (unsigned i = 0, e = Decomposed.VarIndices.size(); i != e; ++i) {
460 if (Decomposed.VarIndices[i].V == Index &&
464 if (Decomposed.VarIndices[i].V == Index &&
461465 Decomposed.VarIndices[i].ZExtBits == ZExtBits &&
462466 Decomposed.VarIndices[i].SExtBits == SExtBits) {
463467 Scale += Decomposed.VarIndices[i].Scale;
478482 }
479483
480484 // Take care of wrap-arounds
481 Decomposed.StructOffset =
482 adjustToPointerSize(Decomposed.StructOffset, PointerSize);
483 Decomposed.OtherOffset =
484 adjustToPointerSize(Decomposed.OtherOffset, PointerSize);
485 if (GepHasConstantOffset) {
486 Decomposed.StructOffset =
487 adjustToPointerSize(Decomposed.StructOffset, PointerSize);
488 Decomposed.OtherOffset =
489 adjustToPointerSize(Decomposed.OtherOffset, PointerSize);
490 }
485491
486492 // Analyze the base pointer next.
487493 V = GEPOp->getOperand(0);
0 ; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
1
2 target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
3 target triple = "i386-apple-macosx10.6.0"
4
5 ; The load and store address in the loop body could alias so the load
6 ; can't be hoisted above the store and out of the loop.
7
8 declare void @llvm.memset.p0i8.i32(i8* nocapture writeonly, i8, i32, i32, i1)
9
10 define i32 @foo(i32 %x, i32 %z, i32 %n) {
11 entry:
12 %pool = alloca [59 x i32], align 4
13 %tmp = bitcast [59 x i32]* %pool to i8*
14 call void @llvm.memset.p0i8.i32(i8* nonnull %tmp, i8 0, i32 236, i32 4, i1 false)
15 %cmp3 = icmp eq i32 %n, 0
16 br i1 %cmp3, label %for.end, label %for.body.lr.ph
17
18 for.body.lr.ph: ; preds = %entry
19 %add = add i32 %z, %x
20 %and = and i32 %add, 2147483647
21 %sub = add nsw i32 %and, -2137521902
22 %arrayidx = getelementptr inbounds [59 x i32], [59 x i32]* %pool, i32 0, i32 %sub
23 %arrayidx1 = getelementptr inbounds [59 x i32], [59 x i32]* %pool, i32 0, i32 42
24 br label %for.body
25
26 for.body: ; preds = %for.body.lr.ph, %for.body
27 %i.04 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
28 store i32 %i.04, i32* %arrayidx, align 4
29 %tmp1 = load i32, i32* %arrayidx1, align 4
30 %inc = add nuw i32 %i.04, 1
31 %exitcond = icmp ne i32 %inc, %n
32 br i1 %exitcond, label %for.body, label %for.end.loopexit
33
34 for.end.loopexit: ; preds = %for.body
35 %lcssa = phi i32 [ %tmp1, %for.body ]
36 br label %for.end
37
38 for.end: ; preds = %for.end.loopexit, %entry
39 %s = phi i32 [ 0, %entry ], [ %lcssa, %for.end.loopexit ]
40 ; CHECK: ret i32 %s
41 ret i32 %s
42 }