[llvm-commits] [llvm] r47541 - in /llvm/trunk: lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll test/Transforms/GVN/memcpy.ll

Owen Anderson resistor at mac.com
Sun Feb 24 16:40:42 PST 2008


Author: resistor
Date: Sun Feb 24 18:40:41 2008
New Revision: 47541

URL: http://llvm.org/viewvc/llvm-project?rev=47541&view=rev
Log:
Fix an issue where GVN would try to use an instruction before its definition when performing return slot optimization.

Added:
    llvm/trunk/test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp
    llvm/trunk/test/Transforms/GVN/memcpy.ll

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=47541&r1=47540&r2=47541&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sun Feb 24 18:40:41 2008
@@ -1099,6 +1099,13 @@
       !CS.paramHasAttr(1, ParamAttr::NoAlias | ParamAttr::StructRet))
     return false;
   
+  // Since we're changing the parameter to the callsite, we need to make sure
+  // that what would be the new parameter dominates the callsite.
+  DominatorTree& DT = getAnalysis<DominatorTree>();
+  if (Instruction* cpyDestInst = dyn_cast<Instruction>(cpyDest))
+    if (!DT.dominates(cpyDestInst, C))
+      return false;
+  
   // Check that something sneaky is not happening involving casting
   // return slot types around.
   if (CS.getArgument(0)->getType() != cpyDest->getType())

Added: llvm/trunk/test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll?rev=47541&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll (added)
+++ llvm/trunk/test/Transforms/GVN/2008-02-24-NonDominatedMemcpy.ll Sun Feb 24 18:40:41 2008
@@ -0,0 +1,25 @@
+; RUN: llvm-as < %s | opt -gvn -dse | llvm-dis | grep {call.*memcpy} | count 1
+
+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-apple-darwin8"
+	%struct.ggFrame3 = type { %struct.ggPoint3, %struct.ggONB3 }
+	%struct.ggHMatrix3 = type { [4 x [4 x double]] }
+	%struct.ggONB3 = type { %struct.ggPoint3, %struct.ggPoint3, %struct.ggPoint3 }
+	%struct.ggPoint3 = type { [3 x double] }
+	%struct.ggQuaternion = type { [4 x double], i32, %struct.ggHMatrix3 }
+
+declare void @llvm.memcpy.i64(i8*, i8*, i64, i32) nounwind 
+
+define void @_Z10ggCRSplineRK8ggFrame3S1_S1_S1_d(%struct.ggFrame3* noalias sret  %agg.result, %struct.ggFrame3* %f0, %struct.ggFrame3* %f1, %struct.ggFrame3* %f2, %struct.ggFrame3* %f3, double %t) nounwind  {
+entry:
+	%qresult = alloca %struct.ggQuaternion		; <%struct.ggQuaternion*> [#uses=1]
+	%tmp = alloca %struct.ggONB3		; <%struct.ggONB3*> [#uses=2]
+	call void @_ZN12ggQuaternion7getONB3Ev( %struct.ggONB3* noalias sret  %tmp, %struct.ggQuaternion* %qresult ) nounwind 
+	%tmp1.i = getelementptr %struct.ggFrame3* %agg.result, i32 0, i32 1		; <%struct.ggONB3*> [#uses=1]
+	%tmp13.i = bitcast %struct.ggONB3* %tmp1.i to i8*		; <i8*> [#uses=1]
+	%tmp24.i = bitcast %struct.ggONB3* %tmp to i8*		; <i8*> [#uses=1]
+	call void @llvm.memcpy.i64( i8* %tmp13.i, i8* %tmp24.i, i64 72, i32 8 ) nounwind 
+	ret void
+}
+
+declare void @_ZN12ggQuaternion7getONB3Ev(%struct.ggONB3* noalias sret , %struct.ggQuaternion*) nounwind 

Modified: llvm/trunk/test/Transforms/GVN/memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/memcpy.ll?rev=47541&r1=47540&r2=47541&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/GVN/memcpy.ll (original)
+++ llvm/trunk/test/Transforms/GVN/memcpy.ll Sun Feb 24 18:40:41 2008
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -gvn -dse | llvm-dis | grep memcpy | count 2
+; RUN: llvm-as < %s | opt -gvn -dse | llvm-dis | grep {call.*memcpy} | count 1
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
 target triple = "i686-apple-darwin9"





More information about the llvm-commits mailing list