Skip to content

Commit d29ed0b

Browse files
committed
Fix an issue where GVN had the sizes of the two memcpy's reverse, resulting
in an invalid transformation. llvm-svn: 47639
1 parent 448538d commit d29ed0b

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,8 @@ bool GVN::processMemCpy(MemCpyInst* M, MemCpyInst* MDep,
11881188
if (!C1 || !C2)
11891189
return false;
11901190

1191-
uint64_t CpySize = C1->getValue().getZExtValue();
1192-
uint64_t DepSize = C2->getValue().getZExtValue();
1191+
uint64_t DepSize = C1->getValue().getZExtValue();
1192+
uint64_t CpySize = C2->getValue().getZExtValue();
11931193

11941194
if (DepSize < CpySize)
11951195
return false;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: llvm-as < %s | opt -gvn -dse | llvm-dis | grep {call.*memcpy.*cell} | count 2
2+
3+
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"
4+
target triple = "i686-apple-darwin9"
5+
%struct.s = type { [11 x i8], i32 }
6+
@.str = internal constant [11 x i8] c"0123456789\00" ; <[11 x i8]*> [#uses=1]
7+
@cell = weak global %struct.s zeroinitializer ; <%struct.s*> [#uses=2]
8+
9+
declare i32 @check(%struct.s* byval %p) nounwind
10+
11+
declare i32 @strcmp(i8*, i8*) nounwind readonly
12+
13+
define i32 @main() noreturn nounwind {
14+
entry:
15+
%p = alloca %struct.s, align 8 ; <%struct.s*> [#uses=2]
16+
store i32 99, i32* getelementptr (%struct.s* @cell, i32 0, i32 1), align 4
17+
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 )
18+
%tmp = getelementptr %struct.s* %p, i32 0, i32 0, i32 0 ; <i8*> [#uses=2]
19+
call void @llvm.memcpy.i64( i8* %tmp, i8* getelementptr (%struct.s* @cell, i32 0, i32 0, i32 0), i64 16, i32 8 )
20+
%tmp1.i = getelementptr %struct.s* %p, i32 0, i32 1 ; <i32*> [#uses=1]
21+
%tmp2.i = load i32* %tmp1.i, align 4 ; <i32> [#uses=1]
22+
%tmp3.i = icmp eq i32 %tmp2.i, 99 ; <i1> [#uses=1]
23+
br i1 %tmp3.i, label %bb5.i, label %bb
24+
25+
bb5.i: ; preds = %entry
26+
%tmp91.i = call i32 @strcmp( i8* %tmp, i8* getelementptr ([11 x i8]* @.str, i32 0, i32 0) ) nounwind readonly ; <i32> [#uses=1]
27+
%tmp53 = icmp eq i32 %tmp91.i, 0 ; <i1> [#uses=1]
28+
br i1 %tmp53, label %bb7, label %bb
29+
30+
bb: ; preds = %bb5.i, %entry
31+
call void @abort( ) noreturn nounwind
32+
unreachable
33+
34+
bb7: ; preds = %bb5.i
35+
call void @exit( i32 0 ) noreturn nounwind
36+
unreachable
37+
}
38+
39+
declare void @llvm.memcpy.i32(i8*, i8*, i32, i32) nounwind
40+
41+
declare void @abort() noreturn nounwind
42+
43+
declare void @exit(i32) noreturn nounwind
44+
45+
declare void @llvm.memcpy.i64(i8*, i8*, i64, i32) nounwind

0 commit comments

Comments
 (0)