Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix mismatched type IND(LCL_VAR_ADDR) folding in RewriteSIMDOperand#27748

Merged
CarolEidt merged 2 commits intodotnet:masterfrom
mikedn:simd-fold
Nov 8, 2019
Merged

Fix mismatched type IND(LCL_VAR_ADDR) folding in RewriteSIMDOperand#27748
CarolEidt merged 2 commits intodotnet:masterfrom
mikedn:simd-fold

Conversation

@mikedn
Copy link

@mikedn mikedn commented Nov 7, 2019

If the indirection and the variable have different SIMD types then a LCL_FLD node of the appropiate type is needed instead of a LCL_VAR node.

Fixes #27405

If the indirection and the variable have different SIMD types then a LCL_FLD node of the appropiate type is needed instead of a LCL_VAR node.
@AaronRobinsonMSFT
Copy link
Member

/cc @dotnet/jit-contrib

@BruceForstall BruceForstall requested a review from a team November 8, 2019 17:58
{
BlockRange().Remove(tree);

addr->SetOper(loadForm(addr->OperGet()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genTreeOps loadForm(genTreeOps addrForm) is unused after that change, could you please delete it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, didn't notice it's no longer need. Thanks!

// If we have GT_IND(GT_LCL_VAR_ADDR) and the var is a SIMD type,
// replace the expression by GT_LCL_VAR or GT_LCL_FLD.
GenTree* addr = tree->AsIndir()->Addr();
if (addr->OperIsLocalAddr() && comp->isAddrOfSIMDType(addr))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like before it could process both GT_IND(GT_LCL_FLD_ADDR(GT_LCL_FLD)) and GT_IND(GT_LCL_VAR_ADDR(LCL_VAR)), but now it is limited to the second option.
Was it intentional? Does it produce diffs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GT_LCL_FLD_ADDR was rejected by isAddrOfSIMDType. That's also the reason I got rid of the call to isAddrOfSIMDType.

addr->AsLclFld()->gtLclOffs = 0;
addr->AsLclFld()->gtFieldSeq = FieldSeqStore::NotAField();

if (((addr->gtFlags & GTF_VAR_DEF) != 0) && (genTypeSize(simdType) < genTypeSize(lclType)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we see genTypeSize(simdType) > genTypeSize(lclType) here? Probably not because you can't do Unsafe.As<Vector3, Vector4>(ref c); , but if yes then you can use bool GenTree::IsPartialLclFld(Compiler* comp) here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's possible, but the result will be undefined. If it's a local variable you may end up overwriting another local variable but that's not something that liveness would ever care about.

The USEASG case is special - if this isn't set correctly, liveness will believe that the entire variable was written to and it will eliminate any previous stores as dead.

BTW, I'm not sure if this particular case is ever hit. It seems technically possible to hit a VAR_DEF but I haven't been able to construct a case showing this so I only added this code out of caution. I hope that eventually we will get rid of the entire function, all this logic should be either in morph or in lowering.

Copy link

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - happy to see the elimination of loadForm

@CarolEidt CarolEidt merged commit a0bbdf9 into dotnet:master Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Converting a Vector4 to a Vector3 using ref asserts

4 participants