Fabio Pagani via llvm-dev
2016-Feb-29 22:06 UTC
[llvm-dev] X86 Backend - How to push and pop eflags?
Hello llvm-dev list, i am implementing an X86 Machine Pass that at some point needs to push/pop eflags on the stack. This pass is hooked at preRegAlloc and LLVM is 3.7.0. I got two big problems: 1) I didn't found a way to emit a pushfq instruction in a clean way, i.e. with BuildMI(*MBB, MI, DL, TII.get(X86::PUSHF64)). Even if both EFLAGS and RSP are added to the MBB liveins, the Machine Verifier complains saying: *** Bad machine code: Using an undefined physical register *** - function: main - basic block: BB#238 for.inc.121.4 (0x43133b0) - instruction: PUSHF64- operand 2: %EFLAGS<imp-use,kill> Anyway right now i'm able to push it via some "dirty" INLINE_ASM. 2) INLINE_ASM works pretty well, except in one randomly generated test case where the register allocator spills a register in between the pushfq/popfq, resulting in a crash of the compiled application. So the question is: is there a recommended way to save and restore the value of eflags? Any help is really appreciated! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160229/48d85701/attachment-0001.html>
Reid Kleckner via llvm-dev
2016-Mar-01 02:11 UTC
[llvm-dev] X86 Backend - How to push and pop eflags?
I think our PUSHF representation or the verifier needs to be changed here. You are lowering it exactly the way that llvm.x86.flags.read.u64 is lowered. Compiling this IR with llc gives the same verifier failure: define i64 @f() { entry: %0 = call i64 @llvm.x86.flags.read.u64() ret i64 %0 } On Mon, Feb 29, 2016 at 2:06 PM, Fabio Pagani via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello llvm-dev list, > > i am implementing an X86 Machine Pass that at some point needs to push/pop > eflags on the stack. This pass is hooked at preRegAlloc and LLVM is 3.7.0. > I got two big problems: > 1) I didn't found a way to emit a pushfq instruction in a clean way, i.e. > with BuildMI(*MBB, MI, DL, TII.get(X86::PUSHF64)). Even if both EFLAGS > and RSP are added to the MBB liveins, the Machine Verifier complains saying: > *** Bad machine code: Using an undefined physical register *** > > - function: main > > - basic block: BB#238 for.inc.121.4 (0x43133b0) > - instruction: PUSHF64- operand 2: %EFLAGS<imp-use,kill> > > Anyway right now i'm able to push it via some "dirty" INLINE_ASM. > > 2) INLINE_ASM works pretty well, except in one randomly generated test > case where the register allocator spills a register in between the > pushfq/popfq, resulting in a crash of the compiled application. > > So the question is: is there a recommended way to save and restore the > value of eflags? > > Any help is really appreciated! > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160229/a4942c56/attachment.html>
David Majnemer via llvm-dev
2016-Mar-02 07:22 UTC
[llvm-dev] X86 Backend - How to push and pop eflags?
On Mon, Feb 29, 2016 at 2:06 PM, Fabio Pagani via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello llvm-dev list, > > i am implementing an X86 Machine Pass that at some point needs to push/pop > eflags on the stack. This pass is hooked at preRegAlloc and LLVM is 3.7.0. > I got two big problems: > 1) I didn't found a way to emit a pushfq instruction in a clean way, i.e. > with BuildMI(*MBB, MI, DL, TII.get(X86::PUSHF64)). Even if both EFLAGS > and RSP are added to the MBB liveins, the Machine Verifier complains saying: > *** Bad machine code: Using an undefined physical register *** > > - function: main > > - basic block: BB#238 for.inc.121.4 (0x43133b0) > - instruction: PUSHF64- operand 2: %EFLAGS<imp-use,kill> >We had a similar issue with the machine verifier for our blessed intrinsic. The fixe was to mark the EFLAGS MachineOperand as Undef: https://github.com/llvm-mirror/llvm/commit/60cefca131b1e4847f7206f99f334baac95772e9> > Anyway right now i'm able to push it via some "dirty" INLINE_ASM. > > 2) INLINE_ASM works pretty well, except in one randomly generated test > case where the register allocator spills a register in between the > pushfq/popfq, resulting in a crash of the compiled application. > > So the question is: is there a recommended way to save and restore the > value of eflags? > > Any help is really appreciated! > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160301/7f2ddf34/attachment.html>