[llvm-commits] [llvm] r61469 - in /llvm/trunk: lib/Transforms/IPO/AddReadAttrs.cpp test/Transforms/AddReadAttrs/2008-12-29-Constant.ll

Duncan Sands baldrick at free.fr
Mon Dec 29 03:34:21 PST 2008


Author: baldrick
Date: Mon Dec 29 05:34:09 2008
New Revision: 61469

URL: http://llvm.org/viewvc/llvm-project?rev=61469&view=rev
Log:
Allow readnone functions to read (and write!) global
constants, since doing so is irrelevant for aliasing
purposes.  While this doesn't increase the total number
of functions marked readonly or readnone in MultiSource/
Applications (3089), it does result in 12 functions being
marked readnone rather than readonly.
Before:
  readnone: 820
  readonly: 2269
After:
  readnone: 832
  readonly: 2257

Added:
    llvm/trunk/test/Transforms/AddReadAttrs/2008-12-29-Constant.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp

Modified: llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp?rev=61469&r1=61468&r2=61469&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/AddReadAttrs.cpp Mon Dec 29 05:34:09 2008
@@ -17,6 +17,7 @@
 #define DEBUG_TYPE "addreadattrs"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/CallGraphSCCPass.h"
+#include "llvm/GlobalVariable.h"
 #include "llvm/Instructions.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -40,6 +41,8 @@
       AU.setPreservesCFG();
       CallGraphSCCPass::getAnalysisUsage(AU);
     }
+
+    bool PointsToLocalMemory(Value *V);
   };
 }
 
@@ -50,6 +53,20 @@
 Pass *llvm::createAddReadAttrsPass() { return new AddReadAttrs(); }
 
 
+/// PointsToLocalMemory - Returns whether the given pointer value points to
+/// memory that is local to the function.  Global constants are considered
+/// local to all functions.
+bool AddReadAttrs::PointsToLocalMemory(Value *V) {
+  V = V->getUnderlyingObject();
+  // An alloca instruction defines local memory.
+  if (isa<AllocaInst>(V))
+    return true;
+  // A global constant counts as local memory for our purposes.
+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+    return GV->isConstant();
+  return false;
+}
+
 bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
   SmallPtrSet<CallGraphNode *, 8> SCCNodes;
   CallGraph &CG = getAnalysis<CallGraph>();
@@ -96,14 +113,12 @@
         if (SCCNodes.count(CG[CS.getCalledFunction()]))
           continue;
       } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
-        Value *Target = LI->getPointerOperand()->getUnderlyingObject();
         // Ignore loads from local memory.
-        if (isa<AllocaInst>(Target))
+        if (PointsToLocalMemory(LI->getPointerOperand()))
           continue;
       } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
-        Value *Target = SI->getPointerOperand()->getUnderlyingObject();
         // Ignore stores to local memory.
-        if (isa<AllocaInst>(Target))
+        if (PointsToLocalMemory(SI->getPointerOperand()))
           continue;
       }
 

Added: llvm/trunk/test/Transforms/AddReadAttrs/2008-12-29-Constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AddReadAttrs/2008-12-29-Constant.ll?rev=61469&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/AddReadAttrs/2008-12-29-Constant.ll (added)
+++ llvm/trunk/test/Transforms/AddReadAttrs/2008-12-29-Constant.ll Mon Dec 29 05:34:09 2008
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | opt -addreadattrs | llvm-dis | grep readnone
+
+ at s = external constant i8		; <i8*> [#uses=1]
+
+define i8 @f() {
+	%tmp = load i8* @s		; <i8> [#uses=1]
+	ret i8 %tmp
+}





More information about the llvm-commits mailing list