[llvm] r226708 - InstCombine: Don't strip bitcasts off of callsites marked 'thunk'
David Majnemer
david.majnemer at gmail.com
Wed Jan 21 14:32:04 PST 2015
Author: majnemer
Date: Wed Jan 21 16:32:04 2015
New Revision: 226708
URL: http://llvm.org/viewvc/llvm-project?rev=226708&view=rev
Log:
InstCombine: Don't strip bitcasts off of callsites marked 'thunk'
The return type of a thunk is meaningless, we just want the arguments
and return value to be forwarded.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/call-cast-target.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Jan 21 16:32:04 2015
@@ -1381,6 +1381,10 @@ bool InstCombiner::transformConstExprCas
dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
if (!Callee)
return false;
+ // The prototype of thunks are a lie, don't try to directly call such
+ // functions.
+ if (Callee->hasFnAttribute("thunk"))
+ return false;
Instruction *Caller = CS.getInstruction();
const AttributeSet &CallerPAL = CS.getAttributes();
Modified: llvm/trunk/test/Transforms/InstCombine/call-cast-target.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/call-cast-target.ll?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/call-cast-target.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/call-cast-target.ll Wed Jan 21 16:32:04 2015
@@ -61,3 +61,14 @@ entry:
%call = tail call i32 bitcast (i32 (i64)* @fn3 to i32 (i32*)*)(i32* %a)
ret i32 %call
}
+
+declare i32 @fn4(i32) "thunk"
+
+define i32 @test4(i32* %a) {
+; CHECK-LABEL: @test4
+; CHECK: %[[call:.*]] = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a)
+; CHECK-NEXT: ret i32 %[[call]]
+entry:
+ %call = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a)
+ ret i32 %call
+}
More information about the llvm-commits
mailing list