Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -8550,6 +8550,36 @@ OpInfo.Type == InlineAsm::isClobber) continue; + // TODO: Current arch of inline asm is not friendly to add special action + // for special instructions. So we add an unstandard/temp fix here, we + // need to refine it. + // + // Currently Clang will generate call func_name with "*m" constrain and + // "func_type * @func_name" in inlineasm. + // Not "m" + "func_type * @func_name" or "*m" + "func_type ** func". + // So backend we have 1 more time "load". + // + // For example: (clang -S -fasm-blocks -emit-llvm -fpic test.c) + // test.c: + // extern void func (); void foo () { __asm{ call sincos_asm; ret \n }; } + // + // will generate: + // IR: + // call void asm sideeffect inteldialect "call qword ptr ${0:P}", + // "*m,~{dirflag},~{fpsr},~{flags}"(void (...)* @func) + // asm: + // movq func@GOTPCREL(%rip), %rax \n callq *(%rax) + // + // we should directly "call *%rax" not "callq *(%rax)" + // + // So, here we manuly change the "*m" to "m". + if (OpInfo.CallOperand.getNode() + && TLI.isPositionIndependent() + && DAG.getSubtarget().getTargetTriple().isX86() + && OpInfo.CallOperand.getOpcode() == ISD::GlobalAddress + && OpInfo.CallOperandVal->getValueID() == Value::FunctionVal) + OpInfo.isIndirect = false; + // If this is a memory input, and if the operand is not indirect, do what we // need to provide an address for the memory input. if (OpInfo.ConstraintType == TargetLowering::C_Memory && Index: llvm/test/CodeGen/X86/semantic-interposition-asm.ll =================================================================== --- llvm/test/CodeGen/X86/semantic-interposition-asm.ll +++ llvm/test/CodeGen/X86/semantic-interposition-asm.ll @@ -61,9 +61,10 @@ ; CHECK-LABEL: test_fun: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: movq fun1@GOTPCREL(%rip), %rax +; CHECK-NEXT: movq %rax, -{{[0-9]+}}(%rsp) ; CHECK-NEXT: #APP ; CHECK-NEXT: movq .Lfun0$local(%rip), %rax -; CHECK-NEXT: movq (%rax), %rax +; CHECK-NEXT: movq -{{[0-9]+}}(%rsp), %rax ; CHECK-NEXT: #NO_APP ; CHECK-NEXT: retq entry: