llvm.org GIT mirror llvm / 4cb3366
BasicAA should look through functions with returned arguments Motivated by the work on the llvm.noalias intrinsic, teach BasicAA to look through returned-argument functions when answering queries. This is essential so that we don't loose all other AA information when supplementing with llvm.noalias. Differential Revision: http://reviews.llvm.org/D9383 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275035 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 3 years ago
4 changed file(s) with 77 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
375375
376376 const GEPOperator *GEPOp = dyn_cast(Op);
377377 if (!GEPOp) {
378 if (auto CS = ImmutableCallSite(V))
379 if (const Value *RV = CS.getReturnedArgOperand()) {
380 V = RV;
381 continue;
382 }
383
378384 // If it's not a GEP, hand it off to SimplifyInstruction to see if it
379385 // can come up with something. This matches what GetUnderlyingObject does.
380386 if (const Instruction *I = dyn_cast(V))
816822 uint64_t V2Size,
817823 const DataLayout &DL) {
818824
819 assert(GEP1->getPointerOperand() == GEP2->getPointerOperand() &&
825 assert(GEP1->getPointerOperand()->stripPointerCasts() ==
826 GEP2->getPointerOperand()->stripPointerCasts() &&
827 GEP1->getPointerOperand()->getType() ==
828 GEP2->getPointerOperand()->getType() &&
820829 "Expected GEPs with the same pointer operand");
821830
822831 // Try to determine whether GEP1 and GEP2 index through arrays, into structs,
10741083 // If we know the two GEPs are based off of the exact same pointer (and not
10751084 // just the same underlying object), see if that tells us anything about
10761085 // the resulting pointers.
1077 if (GEP1->getPointerOperand() == GEP2->getPointerOperand()) {
1086 if (GEP1->getPointerOperand()->stripPointerCasts() ==
1087 GEP2->getPointerOperand()->stripPointerCasts() &&
1088 GEP1->getPointerOperand()->getType() ==
1089 GEP2->getPointerOperand()->getType()) {
10781090 AliasResult R = aliasSameBasePointerGEPs(GEP1, V1Size, GEP2, V2Size, DL);
10791091 // If we couldn't find anything interesting, don't abandon just yet.
10801092 if (R != MayAlias)
29802980 return V;
29812981 V = GA->getAliasee();
29822982 } else {
2983 if (auto CS = CallSite(V))
2984 if (Value *RV = CS.getReturnedArgOperand()) {
2985 V = RV;
2986 continue;
2987 }
2988
29832989 // See if InstructionSimplify knows any relevant tricks.
29842990 if (Instruction *I = dyn_cast(V))
29852991 // TODO: Acquire a DominatorTree and AssumptionCache and use them.
463463 return V;
464464 V = GA->getAliasee();
465465 } else {
466 if (auto CS = CallSite(V))
467 if (Value *RV = CS.getReturnedArgOperand()) {
468 V = RV;
469 continue;
470 }
471
466472 return V;
467473 }
468474 assert(V->getType()->isPointerTy() && "Unexpected operand type!");
512518 } else if (GlobalAlias *GA = dyn_cast(V)) {
513519 V = GA->getAliasee();
514520 } else {
521 if (auto CS = CallSite(V))
522 if (Value *RV = CS.getReturnedArgOperand()) {
523 V = RV;
524 continue;
525 }
526
515527 return V;
516528 }
517529 assert(V->getType()->isPointerTy() && "Unexpected operand type!");
0 ; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3
4 %struct = type { i32, i32, i32 }
5
6 ; CHECK-LABEL: test_simple
7
8 ; CHECK-DAG: MustAlias: %struct* %st, %struct* %sta
9
10 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %x
11 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %y
12 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %z
13
14 ; CHECK-DAG: NoAlias: i32* %x, i32* %y
15 ; CHECK-DAG: NoAlias: i32* %x, i32* %z
16 ; CHECK-DAG: NoAlias: i32* %y, i32* %z
17
18 ; CHECK-DAG: PartialAlias: %struct* %st, %struct* %y_12
19 ; CHECK-DAG: PartialAlias: %struct* %y_12, i32* %x
20 ; CHECK-DAG: PartialAlias: i32* %x, i80* %y_10
21
22 ; CHECK-DAG: PartialAlias: %struct* %st, i64* %y_8
23 ; CHECK-DAG: PartialAlias: i32* %z, i64* %y_8
24 ; CHECK-DAG: NoAlias: i32* %x, i64* %y_8
25
26 ; CHECK-DAG: MustAlias: %struct* %y_12, i32* %y
27 ; CHECK-DAG: MustAlias: i32* %y, i64* %y_8
28 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
29
30 define void @test_simple(%struct* %st, i64 %i, i64 %j, i64 %k) {
31 %x = getelementptr %struct, %struct* %st, i64 %i, i32 0
32 %y = getelementptr %struct, %struct* %st, i64 %j, i32 1
33 %sta = call %struct* @func2(%struct* %st)
34 %z = getelementptr %struct, %struct* %sta, i64 %k, i32 2
35 %y_12 = bitcast i32* %y to %struct*
36 %y_10 = bitcast i32* %y to i80*
37 %ya = call i32* @func1(i32* %y)
38 %y_8 = bitcast i32* %ya to i64*
39 ret void
40 }
41
42 declare i32* @func1(i32* returned) nounwind
43 declare %struct* @func2(%struct* returned) nounwind
44