You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additions
Yeah, this one matches the second condition in the if above (op2 is contained) and it doesn't set the isCommutative value. I couldn't tell why the first and last branches set it but the middle two don't.
We start off with (x * y) + z which will choose 213 ((op2 * op1) + op3 where op1 = x; op2 = y; op3 = z). This form allows op1 and op2 to be swapped and op3 to be contained. In this case, op3 didn't need to be (or couldn't be) contained so we checked op2 instead and determined it could be contained, thus selecting 132 ((op1 * op3) + op2 where op1 = x; op2 = y; op3 = z) instead.
Here's a quick one. fmaTest1 shows the vfmadd132 variant with the movaps right after. fmaTest2 shows the desired vfmadd231. Couple of other codegen issues here as well... this is on preview3, so I'm not sure if they've been fixed since.
Right now we are waiting on choosing the instruction until codegen and do that based on which operand is contained. I'm not sure we have an easier way to do that and I'm not sure that it would help even if we could. sorry, we choose this in lowering and it would likely benefit if we could delay it until codegen, is what I meant to say.
But, I'm not sure we have something tracking the former (that is, being able to say any node can be contained; but we need to ultimately decide on just 1 of them based on the register allocators choices).
Maybe @CarolEidt has some ideas here (but I would guess this is unlikely for 3.0).
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additions
Activity
tannergooding commentedon Mar 8, 2019
This shouldn't be the case. We have a check here: https://github.com/dotnet/coreclr/blob/master/src/jit/hwintrinsiccodegenxarch.cpp#L2354
Could you share a minimal repro I could look at?
saucecontrol commentedon Mar 8, 2019
Yeah, this one matches the second condition in the
ifabove (op2 is contained) and it doesn't set theisCommutativevalue. I couldn't tell why the first and last branches set it but the middle two don't.tannergooding commentedon Mar 8, 2019
I'm not sure why that is missing either, let me test out a fix real quick.
saucecontrol commentedon Mar 8, 2019
Cool, I can make up a repro if that would help. I can confirm that swapping the first two arguments in my example causes
vfmadd231psto be emitted.tannergooding commentedon Mar 8, 2019
A repro that I can directly test would be helpful 😄. Otherwise, I am left just testing the existing tests and local code.
tannergooding commentedon Mar 8, 2019
Ah, right. I remember why this is hard now.
The code right now is choosing:
After the
leais optimized this will be:We start off with
(x * y) + zwhich will choose213((op2 * op1) + op3whereop1 = x; op2 = y; op3 = z). This form allows op1 and op2 to be swapped and op3 to be contained. In this case,op3didn't need to be (or couldn't be) contained so we checkedop2instead and determined it could be contained, thus selecting132((op1 * op3) + op2whereop1 = x; op2 = y; op3 = z) instead.This means we now have
(x * z) + y, which is wrong. We fix this up by swapping op2 and op3 https://github.com/dotnet/coreclr/blob/master/src/jit/hwintrinsiccodegenxarch.cpp#L2331, thus giving us(x * y) + zagain ((op1 * op3) + op2whereop1 = x; op2 = z; op3 = y).Given that
op3is the thing that is contained and and the commutative bits are the things being multiplied, you can't swapop1andop3.saucecontrol commentedon Mar 8, 2019
Here's a quick one.
fmaTest1shows thevfmadd132variant with themovapsright after.fmaTest2shows the desiredvfmadd231. Couple of other codegen issues here as well... this is on preview3, so I'm not sure if they've been fixed since.fmaTest1fmaTest2tannergooding commentedon Mar 8, 2019
(Continued from https://github.com/dotnet/coreclr/issues/23115#issuecomment-470785697)
Right now we are waiting on choosing the instruction until codegen and do that based on which operand is contained. I'm not sure we have an easier way to do that and I'm not sure that it would help even if we could.sorry, we choose this in lowering and it would likely benefit if we could delay it until codegen, is what I meant to say.In the register allocator, we are already not setting a
tgtPrefwhen both operands are commutative, but we do set atgtPrefin the case the operands aren't (for example, we set it toop1for the132case: https://github.com/dotnet/coreclr/blob/master/src/jit/lsraxarch.cpp#L2610).I think the problem is that we aren't really able to tell the register allocator that any of
op1,op2, orop3can be contained; and we would ideally just let the allocator decide what is best and then go off that. Part of this (being able to say more than one node can beregOptional) is tracked here: https://github.com/dotnet/coreclr/issues/6361But, I'm not sure we have something tracking the former (that is, being able to say any node can be contained; but we need to ultimately decide on just
1of them based on the register allocators choices).Maybe @CarolEidt has some ideas here (but I would guess this is unlikely for 3.0).
saucecontrol commentedon Mar 8, 2019
Ah, so it looks like this is a dupe of https://github.com/dotnet/coreclr/issues/20480. Not sure why I didn't see that one when I searched.
AndyAyersMS commentedon Mar 12, 2019
Marking this as future...
saucecontrol commentedon May 21, 2022
This was resolved by #58196