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
While auditing gentree.cpp, I found that GenTreeHWIntrinsic::GetOperForHWIntrinsicId(bool* isScalar, bool getEffectiveOp) tests the isScalarpointer instead of the dereferenced value when refining a GT_SUB into a GT_NEG:
isScalar is the out-param pointer and is always non-null, so this refinement (which is only valid for scalar ops, since IsScalarZero only checks the lowest element) also fires for packed ops. A packed subtract whose constant op1 has a zero low element but is not all-zero — e.g. Vector128.Create(0, 1, 2, 3) - x — is then reported as GT_NEG.
fgOptimizeHWIntrinsic consumes the effective oper for the (-v1) + v2 => v2 - v1 transform (morph.cpp), extracts Op(2) and discards Op(1) (the real constant). The result silently drops the constant for every lane whose value only mattered because the low lane happened to be zero.
While auditing
gentree.cpp, I found thatGenTreeHWIntrinsic::GetOperForHWIntrinsicId(bool* isScalar, bool getEffectiveOp)tests theisScalarpointer instead of the dereferenced value when refining aGT_SUBinto aGT_NEG:isScalaris the out-param pointer and is always non-null, so this refinement (which is only valid for scalar ops, sinceIsScalarZeroonly checks the lowest element) also fires for packed ops. A packed subtract whose constantop1has a zero low element but is not all-zero — e.g.Vector128.Create(0, 1, 2, 3) - x— is then reported asGT_NEG.fgOptimizeHWIntrinsicconsumes the effective oper for the(-v1) + v2 => v2 - v1transform (morph.cpp), extractsOp(2)and discardsOp(1)(the real constant). The result silently drops the constant for every lane whose value only mattered because the low lane happened to be zero.Repro
The fix is to dereference (
*isScalar). This reproduces on currentmainand is latent (found by inspection, not a live report).Note
This issue was authored with the help of GitHub Copilot.