Edmund Grimley-Evans
2010-Oct-08 10:07 UTC
[LLVMdev] Flag output used by two other nodes in DAG
I recently filed this bug: http://llvm.org/bugs/show_bug.cgi?id=8323 It's a dodgy one because you have to patch LLVM to demonstrate it. I suspect that the cause of the problem in that "bug" is that the peephole optimisation in PerformDAGCombine results in a Flag output from one node being used as input by two other nodes in the DAG, and the scheduler then can't cope with that. Is it, or should it be legal for a Flag output to be used as input by more than one other node? If it is legal, does it ever actually work, and, if not, is there already a bug filed relating to this? If it isn't legal, are there sufficient guarantees that it won't happen, and could we please have a better error message if it does happen by accident? In either case, how should the following code get translated in such a way that we don't repeat the comparison? int f1(int x) { return x < 0 ? 11 : x == 0 ? 22 : 33; } Currently, with the ARM back end, I'm getting "cmp r0, #0" repeated. Replace 0 by 100 and I get two instances of "cmpl $100, %edi" in the x86 output, too. Is there already a bug filed relating to that missed optimisation? (Bug 7592 is related to it.) Thanks, Edmund -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Anton Korobeynikov
2010-Oct-08 11:33 UTC
[LLVMdev] Flag output used by two other nodes in DAG
Hello, Edmund,> Is it, or should it be legal for a Flag output to be used as input by > more than one other node?It's illegal. Multiple uses of the flag output do not make any sense, this breaks the semantics of flag operands. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Edmund Grimley-Evans
2010-Oct-08 12:29 UTC
[LLVMdev] Flag output used by two other nodes in DAG
Anton Korobeynikov:> > Is it, or should it be legal for a Flag output to be used as input by > > more than one other node? > It's illegal. Multiple uses of the flag output do not make any sense, > this breaks the semantics of flag operands.All right. Then what should the Selection DAG look like in a case where the flag value generated by one instruction is to be used as input to two other instructions? For a concrete example, consider: int f(int x) { return x < 0 ? 11 : x == 0 ? 22 : 33; } I'd like this to turn into something like what I've seen from other compilers: cmp r0, #0 movlt r0, #11 bxlt lr movne r0, #33 moveq r0, #22 bx lr -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.