Skip to content

Instantly share code, notes, and snippets.

@marijnh
Created September 22, 2011 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marijnh/1235034 to your computer and use it in GitHub Desktop.
Save marijnh/1235034 to your computer and use it in GitHub Desktop.
LLVM optimization issue
; optimize with 'opt -O2 -S' to get the file below. note the undef on line 30 of the result
declare i32 @upcall_rust_personality()
declare i32 @extern_fn(i32*)
define internal void @cleanup_fn() alwaysinline {
ret void
}
define internal fastcc void @wrapper(i32*, i32*) {
%rt = call i32 @extern_fn(i32* %1)
store i32 %rt, i32* %0
ret void
}
define internal fastcc void @wrapper2(i32*, i32*, i32*) noinline {
call fastcc void @wrapper(i32* %0, i32* %1)
ret void
}
define fastcc void @odd_fn(i1*, i32) noinline {
%joinalloc = alloca i32
%retptr1 = alloca i32
%retptr2 = alloca i32
%arg1 = alloca i32
%arg2 = alloca i32
store i32 1, i32* %arg1
store i32 3, i32* %arg2
%test = icmp eq i32 %1, 0
br i1 %test, label %then, label %else
then:
invoke fastcc void @wrapper2(i32* %retptr1, i32* %arg1, i32* %arg2)
to label %called unwind label %unwind
called:
%loadret = load i32* %retptr1
store i32 %loadret, i32* %joinalloc
br label %join
else:
call fastcc void @wrapper(i32* %retptr2, i32* %arg1)
%loadret2 = load i32* %retptr2
store i32 %loadret2, i32* %joinalloc
br label %join
join:
call i32 @extern_fn(i32* %joinalloc)
ret void
unwind:
%land = landingpad { i8*, i32 } personality i32 ()* @upcall_rust_personality
cleanup
call void @cleanup_fn() ; !!!! removing this removes the issue
resume { i8*, i32 } %land
}
; Note how the %storemerge.in.ld phi takes an 'undef', and there's no trace of the load from %retptr1 left
; ModuleID = 'foo.ll'
declare i32 @extern_fn(i32*)
define internal fastcc void @wrapper2(i32* nocapture, i32*) noinline {
%rt.i = tail call i32 @extern_fn(i32* %1)
store i32 %rt.i, i32* %0
ret void
}
define fastcc void @odd_fn(i1* nocapture, i32) noinline {
%joinalloc = alloca i32
%retptr1 = alloca i32
%arg1 = alloca i32
store i32 1, i32* %arg1
%test = icmp eq i32 %1, 0
br i1 %test, label %then, label %else
then: ; preds = %2
call fastcc void @wrapper2(i32* %retptr1, i32* %arg1)
br label %join
else: ; preds = %2
%rt.i = call i32 @extern_fn(i32* %arg1)
br label %join
join: ; preds = %then, %else
%storemerge.in.ld = phi i32 [ %rt.i, %else ], [ undef, %then ]
store i32 %storemerge.in.ld, i32* %joinalloc
%3 = call i32 @extern_fn(i32* %joinalloc)
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment