[llvm] r185776 - Eliminate trivial redundant loads across nocapture+readonly calls to uncaptured

Nick Lewycky nicholas at mxc.ca
Sun Jul 7 03:15:16 PDT 2013


Author: nicholas
Date: Sun Jul  7 05:15:16 2013
New Revision: 185776

URL: http://llvm.org/viewvc/llvm-project?rev=185776&view=rev
Log:
Eliminate trivial redundant loads across nocapture+readonly calls to uncaptured
pointer arguments.

Added:
    llvm/trunk/test/Transforms/GVN/readattrs.ll
Modified:
    llvm/trunk/lib/Analysis/AliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/AliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysis.cpp?rev=185776&r1=185775&r2=185776&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysis.cpp Sun Jul  7 05:15:16 2013
@@ -450,6 +450,7 @@ AliasAnalysis::callCapturesBefore(const
     return AliasAnalysis::ModRef;
 
   unsigned ArgNo = 0;
+  AliasAnalysis::ModRefResult R = AliasAnalysis::NoModRef;
   for (ImmutableCallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
        CI != CE; ++CI, ++ArgNo) {
     // Only look at the no-capture or byval pointer arguments.  If this
@@ -463,12 +464,18 @@ AliasAnalysis::callCapturesBefore(const
     // is impossible to alias the pointer we're checking.  If not, we have to
     // assume that the call could touch the pointer, even though it doesn't
     // escape.
-    if (!isNoAlias(AliasAnalysis::Location(*CI),
-                   AliasAnalysis::Location(Object))) {
-      return AliasAnalysis::ModRef;
+    if (isNoAlias(AliasAnalysis::Location(*CI),
+		  AliasAnalysis::Location(Object)))
+      continue;
+    if (CS.doesNotAccessMemory(ArgNo))
+      continue;
+    if (CS.onlyReadsMemory(ArgNo)) {
+      R = AliasAnalysis::Ref;
+      continue;
     }
+    return AliasAnalysis::ModRef;
   }
-  return AliasAnalysis::NoModRef;
+  return R;
 }
 
 // AliasAnalysis destructor: DO NOT move this to the header file for

Added: llvm/trunk/test/Transforms/GVN/readattrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/readattrs.ll?rev=185776&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/readattrs.ll (added)
+++ llvm/trunk/test/Transforms/GVN/readattrs.ll Sun Jul  7 05:15:16 2013
@@ -0,0 +1,17 @@
+; RUN: opt -gvn -S -o - < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @use(i8* readonly nocapture)
+
+define i8 @test() {
+  %a = alloca i8
+  store i8 1, i8* %a
+  call void @use(i8* %a)
+  %b = load i8* %a
+  ret i8 %b
+; CHECK: define i8 @test
+; CHECK: call void @use(i8* %a)
+; CHECK-NEXT: ret i8 1
+}





More information about the llvm-commits mailing list