Ryan Taylor via llvm-dev
2015-Sep-29 19:25 UTC
[llvm-dev] Duplicating node in SelectionDAG?
It appears that it's impossible to duplicate a node in the dag. For example, there is some code: b = a * a; // a is a global int A LD node is generated for A and it goes into both Operand 0 and 1 of the MUL node. The issue is I'm trying to match a pattern of: set dstReg:$dstD (OpNode (srcAType (load addr32:$srcA)), (srcBType (load addr32:$srcB))) so basically a mem, mem, reg operation. The issue is this pattern won't match in the above example because there is only one LD generated for 'a'. I tried to duplicate the LD in the dag but it doesn't show up, it always reduces it to only one LD no matter what, even if I have multiple loads in the IR also. #1. Is it possible to duplicate an exact copy of a node in the dag? #2. How would I go about matching this pattern in table gen? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150929/d453b3fa/attachment.html>
Matt Arsenault via llvm-dev
2015-Sep-29 20:00 UTC
[llvm-dev] Duplicating node in SelectionDAG?
On 09/29/2015 12:25 PM, Ryan Taylor via llvm-dev wrote:> It appears that it's impossible to duplicate a node in the dag. For > example, there is some code:Correct, nodes are uniqued and CSEd> > b = a * a; // a is a global int > > A LD node is generated for A and it goes into both Operand 0 and 1 of > the MUL node. The issue is I'm trying to match a pattern of: > > set dstReg:$dstD (OpNode (srcAType (load addr32:$srcA)), (srcBType > (load addr32:$srcB))) > > so basically a mem, mem, reg operation. > > The issue is this pattern won't match in the above example because > there is only one LD generated for 'a'. I tried to duplicate the LD in > the dag but it doesn't show up, it always reduces it to only one LD no > matter what, even if I have multiple loads in the IR also. > > #1. Is it possible to duplicate an exact copy of a node in the dag?No> #2. How would I go about matching this pattern in table gen?I would be surprised that patterns that happen to match the same node multiple times as operands wouldn't work as is. Maybe there is some complexity because these nodes have chains added? Have you looked at the generated matching code for why it isn't selecting? If all else fails you should be able to use a ComplexPattern -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150929/6d099b49/attachment.html>
Ryan Taylor via llvm-dev
2015-Sep-29 20:05 UTC
[llvm-dev] Duplicating node in SelectionDAG?
Matt, I would have suspecting the same but it's not matching that. For example: c = a * b; // this matches mem, mem, reg just fine c = a * a; // this does not match Maybe because of the chaining up from the TargetGlobalAddress? but the first example has that also for a and b, it's basically the exact same DAG for those two examples except in a * a there is only one chain leading to the ld (and one ld) and the mul's operand 1 and 2 go to the one load. It would seem to me it's not matching since it expects two load nodes and there is only one. Thanks. On Tue, Sep 29, 2015 at 4:00 PM, Matt Arsenault <Matthew.Arsenault at amd.com> wrote:> On 09/29/2015 12:25 PM, Ryan Taylor via llvm-dev wrote: > > It appears that it's impossible to duplicate a node in the dag. For > example, there is some code: > > Correct, nodes are uniqued and CSEd > > > b = a * a; // a is a global int > > A LD node is generated for A and it goes into both Operand 0 and 1 of the > MUL node. The issue is I'm trying to match a pattern of: > > set dstReg:$dstD (OpNode (srcAType (load addr32:$srcA)), (srcBType (load > addr32:$srcB))) > > so basically a mem, mem, reg operation. > > The issue is this pattern won't match in the above example because there > is only one LD generated for 'a'. I tried to duplicate the LD in the dag > but it doesn't show up, it always reduces it to only one LD no matter what, > even if I have multiple loads in the IR also. > > #1. Is it possible to duplicate an exact copy of a node in the dag? > > No > > #2. How would I go about matching this pattern in table gen? > > I would be surprised that patterns that happen to match the same node > multiple times as operands wouldn't work as is. Maybe there is some > complexity because these nodes have chains added? Have you looked at the > generated matching code for why it isn't selecting? If all else fails you > should be able to use a ComplexPattern >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150929/fb47ec89/attachment.html>
Ryan Taylor via llvm-dev
2015-Oct-02 15:30 UTC
[llvm-dev] Duplicating node in SelectionDAG?
Matt, I guess this is my question. Even for code like this: int a, b, c, d; int main() { c =-a / b; d = a % b; return 0; } It still doesn't match to the pattern: set dstReg:$dstD (OpNode (srcAType (load addr32:$srcA)), (srcBType (load addr32:$srcB))) This one seems more obvious why, the d = a % b could be further down the list and since the DAG is CSE'd it instead generates a copy to a register. I'm not sure a ComplexPattern is going to solve this issue, I would think, given the number of different chains possible. We might need some backend propagation to propagate the memory load down into other instructions. Has on one run into this issue before? This seems surprising. On Tue, Sep 29, 2015 at 4:00 PM, Matt Arsenault <Matthew.Arsenault at amd.com> wrote:> On 09/29/2015 12:25 PM, Ryan Taylor via llvm-dev wrote: > > It appears that it's impossible to duplicate a node in the dag. For > example, there is some code: > > Correct, nodes are uniqued and CSEd > > > b = a * a; // a is a global int > > A LD node is generated for A and it goes into both Operand 0 and 1 of the > MUL node. The issue is I'm trying to match a pattern of: > > set dstReg:$dstD (OpNode (srcAType (load addr32:$srcA)), (srcBType (load > addr32:$srcB))) > > so basically a mem, mem, reg operation. > > The issue is this pattern won't match in the above example because there > is only one LD generated for 'a'. I tried to duplicate the LD in the dag > but it doesn't show up, it always reduces it to only one LD no matter what, > even if I have multiple loads in the IR also. > > #1. Is it possible to duplicate an exact copy of a node in the dag? > > No > > #2. How would I go about matching this pattern in table gen? > > I would be surprised that patterns that happen to match the same node > multiple times as operands wouldn't work as is. Maybe there is some > complexity because these nodes have chains added? Have you looked at the > generated matching code for why it isn't selecting? If all else fails you > should be able to use a ComplexPattern >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151002/abc96c82/attachment.html>