This was ignoring the flag on fneg, and using the source instruction's
flags which wasn't obviously correct looking to me. I think this is
OK, but should also keep any flags present on the original fneg.
Also fixes tests missing from r358702.
Differential D63405
GlobalISel: Don't lose fneg flags when lowering to fsub arsenm on Jun 17 2019, 4:32 AM. Authored by
Details This was ignoring the flag on fneg, and using the source instruction's Also fixes tests missing from r358702.
Diff Detail Event TimelineComment Actions I'm not familiar with how flags are being used in this layer, but union of flags doesn't match the way we deal with FMF in IR. If the fneg is strict (disregard the irrelevant 'arcp' in that last test), then it's invalid to assume that it inherits the 'nsz' property from its operand. Comment Actions I would expect the lowering here to just preserve the flag on the original instruction, and not propagate the source (as was done here previously). The corresponding expansion in the DAG has a TODO to preserve the flags, so there isn't precedent for this Comment Actions Let me know if I'm not seeing this correctly (haven't looked at MIR very much - it might help if the test was committed with the baseline output first, so we just have a diff in this patch). Comment Actions The pre-patch code would fold fneg (fadd flags x, y) -> fsub flags -0.0, (fadd flags x, y), and entirely ignore any flags on fneg. I'm not entirely sure this is correct on its own Comment Actions The original code is wrong then (assuming we're using FMF on a value with the same reasoning that we use in IR/DAG). I'm not seeing how 'union' of flags is the correct fix though. Comment Actions Ok, with the constraint like in the DAG: as Unsafe or nsz on the Op SDAG is preserving the Op flags or in this case the MI flags in place of SrcMI. Comment Actions IIRC, isn't preserving the original flags the outcome we want here? If so, I think the updated patch is fine. @mcberg2017 is that correct? Comment Actions I don't follow. I don't see why the source should matter. The DAG currently does not preserve the flags here Comment Actions I am saying you have it right Matt for using MI flags, but we should guard folding based on Unsafe or nsz in the Flags. Comment Actions We do this as a combine earlier in target specific code under this constraint. Matt, perhaps you just missing that combine in GlobalIsel? Comment Actions AMDGPU doesn't use this legalization. I'm just trying to fix a correctness issue in the generic legalizer Comment Actions So I agree, but I think there should be a target specific combine with guards for Unsafe and nsz and this legalization case (for those who do not have it). Comment Actions I think we should preserve the existing flags and be consistent with what we do in SDAGISel. LGTM. Comment Actions This matches my mental model for FMF propagation, so LGTM. But there's a separate question that is raised here: why is it legal to convert fneg to fsub -0.0? That loosens the IEEE requirement when dealing with a NAN. I'd think this should be legalized by converting to integer and flipping the sign bit (xor). Comment Actions Should this expansion just be ripped out then? This is also broken in SelectionDAG. I don't like the idea of a legalization that relies on checking the flags, and this could be an optimization fold somewhere else |