[llvm-commits] [llvm] r47639 - in /llvm/trunk: lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/2008-02-26-MemCpySize.ll

Owen Anderson resistor at mac.com
Tue Feb 26 15:06:18 PST 2008


Author: resistor
Date: Tue Feb 26 17:06:17 2008
New Revision: 47639

URL: http://llvm.org/viewvc/llvm-project?rev=47639&view=rev
Log:
Fix an issue where GVN had the sizes of the two memcpy's reverse, resulting
in an invalid transformation.

Added:
    llvm/trunk/test/Transforms/GVN/2008-02-26-MemCpySize.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Feb 26 17:06:17 2008
@@ -1188,8 +1188,8 @@
   if (!C1 || !C2)
     return false;
   
-  uint64_t CpySize = C1->getValue().getZExtValue();
-  uint64_t DepSize = C2->getValue().getZExtValue();
+  uint64_t DepSize = C1->getValue().getZExtValue();
+  uint64_t CpySize = C2->getValue().getZExtValue();
   
   if (DepSize < CpySize)
     return false;

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

==============================================================================
--- llvm/trunk/test/Transforms/GVN/2008-02-26-MemCpySize.ll (added)
+++ llvm/trunk/test/Transforms/GVN/2008-02-26-MemCpySize.ll Tue Feb 26 17:06:17 2008
@@ -0,0 +1,45 @@
+; RUN: llvm-as < %s | opt -gvn -dse | llvm-dis | grep {call.*memcpy.*cell} | count 2
+
+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"
+	%struct.s = type { [11 x i8], i32 }
+ at .str = internal constant [11 x i8] c"0123456789\00"		; <[11 x i8]*> [#uses=1]
+ at cell = weak global %struct.s zeroinitializer		; <%struct.s*> [#uses=2]
+
+declare i32 @check(%struct.s* byval  %p) nounwind
+
+declare i32 @strcmp(i8*, i8*) nounwind readonly 
+
+define i32 @main() noreturn nounwind  {
+entry:
+	%p = alloca %struct.s, align 8		; <%struct.s*> [#uses=2]
+	store i32 99, i32* getelementptr (%struct.s* @cell, i32 0, i32 1), align 4
+	call void @llvm.memcpy.i32( i8* getelementptr (%struct.s* @cell, i32 0, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str, i32 0, i32 0), i32 11, i32 1 )
+	%tmp = getelementptr %struct.s* %p, i32 0, i32 0, i32 0		; <i8*> [#uses=2]
+	call void @llvm.memcpy.i64( i8* %tmp, i8* getelementptr (%struct.s* @cell, i32 0, i32 0, i32 0), i64 16, i32 8 )
+	%tmp1.i = getelementptr %struct.s* %p, i32 0, i32 1		; <i32*> [#uses=1]
+	%tmp2.i = load i32* %tmp1.i, align 4		; <i32> [#uses=1]
+	%tmp3.i = icmp eq i32 %tmp2.i, 99		; <i1> [#uses=1]
+	br i1 %tmp3.i, label %bb5.i, label %bb
+
+bb5.i:		; preds = %entry
+	%tmp91.i = call i32 @strcmp( i8* %tmp, i8* getelementptr ([11 x i8]* @.str, i32 0, i32 0) ) nounwind readonly 		; <i32> [#uses=1]
+	%tmp53 = icmp eq i32 %tmp91.i, 0		; <i1> [#uses=1]
+	br i1 %tmp53, label %bb7, label %bb
+
+bb:		; preds = %bb5.i, %entry
+	call void @abort( ) noreturn nounwind 
+	unreachable
+
+bb7:		; preds = %bb5.i
+	call void @exit( i32 0 ) noreturn nounwind 
+	unreachable
+}
+
+declare void @llvm.memcpy.i32(i8*, i8*, i32, i32) nounwind 
+
+declare void @abort() noreturn nounwind 
+
+declare void @exit(i32) noreturn nounwind 
+
+declare void @llvm.memcpy.i64(i8*, i8*, i64, i32) nounwind 





More information about the llvm-commits mailing list