[llvm-commits] [llvm] r51134 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2003-11-13-ConstExprCastCall.ll test/Transforms/InstCombine/fp-ret-bitcast.ll
Duncan Sands
baldrick at free.fr
Fri May 16 07:33:11 PDT 2008
Hi Chris,
> I'm saying that the optimization is important, and was implemented for
> a reason :). The issue is code like this:
>
> --- a.c
> int foo()
> int bar() {
> return foo(1, 2, 3);
> }
> --- b.c
> void foo(int x, int y, int z) { return x+y+z; }
>
>
>
> After llvm-link runs, you get the bitcast of function. It is
> important to have instcombine squash this so that (e.g.) inline can
> see a direct call. However, it should only do this in cases that
> don't violate the ABI :)
in your example you can see the function definition (and not just
a declaration), so doing the transform only when you have the
declaration of the callee to hand would be ok for this example.
Ciao,
Duncan.
PS: I just chucked some code into GlobalOpt that teaches it to change
the type of a declaration if the only use is a bitcast to a function
type. It seems to work! This transforms the objc testcase to:
; ModuleID = 'out.bc'
%struct.NSArray = type { %struct.NSObject }
%struct.NSObject = type { %struct.objc_class* }
%struct.objc_class = type opaque
%struct.objc_selector = type opaque
@"\01L_OBJC_METH_VAR_NAME_112" = internal global [15 x i8] c"whiteComponent\00", section "__TEXT,__cstring,cstring_literals" ; <[15 x i8]*> [#uses=1]
define void @bork() nounwind {
entry:
%color = alloca %struct.NSArray* ; <%struct.NSArray**> [#uses=1]
%color.466 = alloca %struct.NSObject* ; <%struct.NSObject**> [#uses=2]
%tmp103 = load %struct.NSArray** %color, align 4 ; <%struct.NSArray*> [#uses=1]
%tmp103104 = getelementptr %struct.NSArray* %tmp103, i32 0, i32 0 ; <%struct.NSObject*> [#uses=1]
store %struct.NSObject* %tmp103104, %struct.NSObject** %color.466, align 4
%tmp106 = load %struct.NSObject** %color.466, align 4 ; <%struct.NSObject*> [#uses=2]
%tmp107 = call float @objc_msgSend_fpret( %struct.NSObject* %tmp106, %struct.objc_selector* bitcast ([15 x i8]* @"\01L_OBJC_METH_VAR_NAME_112" to %struct.objc_selector*) ) nounwind ; <float> [#uses=0]
%tmp108 = call float @objc_msgSend_fpret( %struct.NSObject* %tmp106, %struct.objc_selector* bitcast ([15 x i8]* @"\01L_OBJC_METH_VAR_NAME_112" to %struct.objc_selector*) ) nounwind ; <float> [#uses=0]
br label %exit
exit: ; preds = %entry
ret void
}
declare float @objc_msgSend_fpret(%struct.NSObject*, %struct.objc_selector*)
More information about the llvm-commits
mailing list