[llvm] r372075 - [Attributor] Use Alias Analysis in noalias callsite argument deduction

Hideto Ueno via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 23:53:28 PDT 2019


Author: uenoku
Date: Mon Sep 16 23:53:27 2019
New Revision: 372075

URL: http://llvm.org/viewvc/llvm-project?rev=372075&view=rev
Log:
[Attributor] Use Alias Analysis in noalias callsite argument deduction

Summary: This patch adds a check of alias analysis in `noalias` callsite argument deduction.

Reviewers: jdoerfert, sstefan1

Reviewed By: jdoerfert

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67604

Modified:
    llvm/trunk/lib/Transforms/IPO/Attributor.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/internal-noalias.ll
    llvm/trunk/test/Transforms/FunctionAttrs/noalias_returned.ll

Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=372075&r1=372074&r2=372075&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Mon Sep 16 23:53:27 2019
@@ -1762,11 +1762,18 @@ struct AANoAliasCallSiteArgument final :
       if (!ArgOp->getType()->isPointerTy())
         continue;
 
-      // TODO: Use AliasAnalysis
-      //       AAResults& AAR = ..;
-      //       if(AAR.isNoAlias(&getAssociatedValue(), ArgOp))
-      //          return indicatePessimitisicFixpoint();
+      if (const Function *F = getAnchorScope()) {
+        if (AAResults *AAR = A.getInfoCache().getAAResultsForFunction(*F)) {
+          LLVM_DEBUG(dbgs()
+                     << "[Attributor][NoAliasCSArg] Check alias between "
+                        "callsite arguments "
+                     << AAR->isNoAlias(&getAssociatedValue(), ArgOp) << " "
+                     << getAssociatedValue() << " " << *ArgOp << "\n");
 
+          if (AAR->isNoAlias(&getAssociatedValue(), ArgOp))
+            continue;
+        }
+      }
       return indicatePessimisticFixpoint();
     }
 

Modified: llvm/trunk/test/Transforms/FunctionAttrs/internal-noalias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/internal-noalias.ll?rev=372075&r1=372074&r2=372075&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/internal-noalias.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/internal-noalias.ll Mon Sep 16 23:53:27 2019
@@ -1,4 +1,4 @@
-; RUN: opt -S -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 < %s | FileCheck %s
 
 define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
 entry:
@@ -10,7 +10,7 @@ entry:
 
 ; FIXME: Should be something like this.
 ; define internal i32 @noalias_args(i32* nocapture readonly %A, i32* noalias nocapture readonly %B)
-; CHECK: define internal i32 @noalias_args(i32* nocapture %A, i32* nocapture %B)
+; CHECK: define internal i32 @noalias_args(i32* nocapture %A, i32* noalias nocapture %B)
 
 define internal i32 @noalias_args(i32* %A, i32* %B) #0 {
 entry:

Modified: llvm/trunk/test/Transforms/FunctionAttrs/noalias_returned.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/noalias_returned.ll?rev=372075&r1=372074&r2=372075&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/noalias_returned.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/noalias_returned.ll Mon Sep 16 23:53:27 2019
@@ -1,4 +1,4 @@
-; RUN: opt -S -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=5 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=5 < %s | FileCheck %s
 
 ; TEST 1 - negative.
 
@@ -203,7 +203,7 @@ define void @test12_1() {
 ; CHECK-NEXT:    [[B:%.*]] = tail call noalias i8* @malloc(i64 4)
 ; CHECK-NEXT:    tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
 ; CHECK-NEXT:    tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
-; CHECK-NEXT:    tail call void @use_nocapture(i8* noalias [[B]])
+; CHECK-NEXT:    tail call void @use_nocapture(i8* noalias nocapture [[B]])
 ; CHECK-NEXT:    tail call void @use_nocapture(i8* noalias [[B]])
 ; CHECK-NEXT:    ret void
 ;
@@ -220,7 +220,7 @@ define void @test12_2(){
 ; CHECK-LABEL: @test12_2(
 ; CHECK-NEXT:    [[A:%.*]] = tail call noalias i8* @malloc(i64 4)
 ; FIXME: This should be @use_nocapture(i8* noalias [[A]])
-; CHECK-NEXT:    tail call void @use_nocapture(i8* [[A]])
+; CHECK-NEXT:    tail call void @use_nocapture(i8* nocapture [[A]])
 ; FIXME: This should be @use_nocapture(i8* noalias [[A]])
 ; CHECK-NEXT:    tail call void @use_nocapture(i8* [[A]])
 ; CHECK-NEXT:    tail call void @use(i8* [[A]])
@@ -239,7 +239,7 @@ declare void @two_args(i8* nocapture , i
 define void @test12_3(){
 ; CHECK-LABEL: @test12_3(
   %A = tail call noalias i8* @malloc(i64 4)
-; CHECK: tail call void @two_args(i8* %A, i8* %A)
+; CHECK: tail call void @two_args(i8* nocapture %A, i8* %A)
   tail call void @two_args(i8* %A, i8* %A)
   ret void
 }
@@ -252,18 +252,17 @@ define void @test12_4(){
   %A_1 = getelementptr i8, i8* %A, i64 1
   %B_0 = getelementptr i8, i8* %B, i64 0
 
-; FIXME: This should be @two_args(i8* noalias %A, i8* noalias %B)
-; CHECK: tail call void @two_args(i8* %A, i8* %B)
+; CHECK: tail call void @two_args(i8* noalias %A, i8* noalias %B)
   tail call void @two_args(i8* %A, i8* %B)
 
-; CHECK: tail call void @two_args(i8* %A, i8* %A_0)
+; CHECK: tail call void @two_args(i8* %A, i8* nocapture %A_0)
   tail call void @two_args(i8* %A, i8* %A_0)
 
 ; CHECK: tail call void @two_args(i8* %A, i8* %A_1)
   tail call void @two_args(i8* %A, i8* %A_1)
 
 ; FIXME: This should be @two_args(i8* noalias %A_0, i8* noalias %B_0)
-; CHECK: tail call void @two_args(i8* %A_0, i8* %B_0)
+; CHECK: tail call void @two_args(i8* %A_0, i8* nocapture %B_0)
   tail call void @two_args(i8* %A_0, i8* %B_0)
   ret void
 }




More information about the llvm-commits mailing list