[llvm] r256959 - [X86] Correctly model TLS calls w.r.t. frame requirements.

Manman Ren via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 11:23:58 PST 2016


Thanks, Quentin.

I will apply the same trick on x86 as AArch64.

Manman


On Wed, Jan 6, 2016 at 11:23 AM, Quentin Colombet <qcolombet at apple.com>
wrote:

> Hi Manman,
>
> Just a heads-up to tell you that the fix for PR25820 landed and as
> discussed before the holidays, this implies poorer codegen for the cxx fast
> TLS calling convention on x86 since shrink-wrapping cannot help you
> anymore. I.e., you need to apply the same tricks that you did for AArch64
> on x86.
>
> Cheers,
> -Quentin
> > On Jan 6, 2016, at 11:09 AM, Quentin Colombet via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
> >
> > Author: qcolombet
> > Date: Wed Jan  6 13:09:26 2016
> > New Revision: 256959
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=256959&view=rev
> > Log:
> > [X86] Correctly model TLS calls w.r.t. frame requirements.
> > TLS calls need the stack frame to be properly set up and this
> > implies that such calls need ADJUSTSTACK_xxx markers.
> >
> > Fixes PR25820.
> >
> > Modified:
> >    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
> >    llvm/trunk/test/CodeGen/X86/cxx_tlscc64.ll
> >    llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll
> >
> > Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=256959&r1=256958&r2=256959&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
> > +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Jan  6 13:09:26
> 2016
> > @@ -12474,8 +12474,12 @@ X86TargetLowering::LowerGlobalTLSAddress
> >     // location.
> >     SDValue Chain = DAG.getEntryNode();
> >     SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
> > +    Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, DL,
> true), DL);
> >     SDValue Args[] = { Chain, Offset };
> >     Chain = DAG.getNode(X86ISD::TLSCALL, DL, NodeTys, Args);
> > +    Chain =
> > +        DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, DL, true),
> > +                           DAG.getIntPtrConstant(0, DL, true),
> SDValue(), DL);
> >
> >     // TLSCALL will be codegen'ed as call. Inform MFI that function has
> calls.
> >     MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
> >
> > Modified: llvm/trunk/test/CodeGen/X86/cxx_tlscc64.ll
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cxx_tlscc64.ll?rev=256959&r1=256958&r2=256959&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/test/CodeGen/X86/cxx_tlscc64.ll (original)
> > +++ llvm/trunk/test/CodeGen/X86/cxx_tlscc64.ll Wed Jan  6 13:09:26 2016
> > @@ -1,5 +1,9 @@
> > ; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
> > -; RUN: llc < %s -mtriple=x86_64-apple-darwin -enable-shrink-wrap=true |
> FileCheck --check-prefix=SHRINK %s
> > +; TLS function were wrongly model and after fixing that, shrink-wrapping
> > +; cannot help here. To achieve the expected lowering, we need to playing
> > +; tricks similar to AArch64 fast TLS calling convention (r255821).
> > +; Re-enable the following run line when
> > +; _RUN_: llc < %s -mtriple=x86_64-apple-darwin -enable-shrink-wrap=true
> | FileCheck --check-prefix=SHRINK %s
> > %struct.S = type { i8 }
> >
> > @sg = internal thread_local global %struct.S zeroinitializer, align 1
> >
> > Modified: llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll?rev=256959&r1=256958&r2=256959&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll (original)
> > +++ llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll Wed Jan  6
> 13:09:26 2016
> > @@ -878,4 +878,48 @@ for.end:
> >
> > declare i32 @varfunc(i8* nocapture readonly)
> >
> > + at sum1 = external hidden thread_local global i32, align 4
> > +
> > +
> > +; Function Attrs: nounwind
> > +; Make sure the TLS call used to access @sum1 happens after the prologue
> > +; and before the epilogue.
> > +; TLS calls used to be wrongly model and shrink-wrapping would have
> inserted
> > +; the prologue and epilogue just around the call to doSomething.
> > +; PR25820.
> > +;
> > +; CHECK-LABEL: tlsCall:
> > +; CHECK: pushq
> > +; CHECK: testb $1, %dil
> > +; CHECK: je [[ELSE_LABEL:LBB[0-9_]+]]
> > +;
> > +; master bb
> > +; CHECK: movq _sum1 at TLVP(%rip), %rdi
> > +; CHECK-NEXT: callq *(%rdi)
> > +; CHECK: jmp [[EXIT_LABEL:LBB[0-9_]+]]
> > +;
> > +; [[ELSE_LABEL]]:
> > +; CHECK: callq _doSomething
> > +;
> > +; [[EXIT_LABEL]]:
> > +; CHECK: popq
> > +; CHECK-NEXT: retq
> > +define i32 @tlsCall(i1 %bool1, i32 %arg, i32* readonly
> dereferenceable(4) %sum1) #3 {
> > +entry:
> > +  br i1 %bool1, label %master, label %else
> > +
> > +master:
> > +  %tmp1 = load i32, i32* %sum1, align 4
> > +  store i32 %tmp1, i32* @sum1, align 4
> > +  br label %exit
> > +
> > +else:
> > +  %call = call i32 @doSomething(i32 0, i32* null)
> > +  br label %exit
> > +
> > +exit:
> > +  %res = phi i32 [ %arg, %master], [ %call, %else ]
> > +  ret i32 %res
> > +}
> > +
> > attributes #3 = { nounwind }
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160106/ea7d5c1f/attachment.html>


More information about the llvm-commits mailing list