This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix incorrect getSetCCInverse usage within trySwapVSelectOperands.
ClosedPublic

Authored by paulwalker-arm on Mar 17 2022, 3:27 PM.

Details

Summary

When inverting the compare predicate trySwapVSelectOperands is
incorrectly using the type of the select's cond operand rather
than the type of cond's operands. This means we're treating all
inversions as if they're integer.

Diff Detail

Unit TestsFailed

Event Timeline

paulwalker-arm created this revision.Mar 17 2022, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 3:27 PM
paulwalker-arm requested review of this revision.Mar 17 2022, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 3:27 PM
david-arm added inline comments.Mar 18 2022, 1:45 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17522

Hi @paulwalker-arm, I actually think this is still wrong because I'm pretty sure we should be using the SetCC's input operand type, i.e.

ISD::getSetCCInverse(CC, SetCC.getOperand(0).getValueType())

The reason is that the setcc may actually use integer operands, i.e.

%p = icmp eq <vscale x 4 x i32> %c, zeroinitializer
%fmul = fmul <vscale x 4 x float> %a, %b
%sel = select <vscale x 4 x i1> %p, <vscale x 4 x float> %a, <vscale x 4 x float> %fmul

In fact, this is not your fault, but I think we're missing some tests for this. I don't see anything in trySwapVSelectOperands that precludes this possibility.

paulwalker-arm added inline comments.Mar 18 2022, 3:00 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17522

Are yes, not sure what I was thinking. Thanks Dave.

Fixed the bug Dave spoted and changed one of the tests to use an integer comparison.

david-arm accepted this revision.Mar 18 2022, 3:42 AM

LGTM! Thanks for making the changes @paulwalker-arm. :)

This revision is now accepted and ready to land.Mar 18 2022, 3:42 AM
paulwalker-arm marked an inline comment as done.Mar 18 2022, 3:42 AM
paulwalker-arm added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17522

Although I've changed one of the tests to use an integer comparison it seems the code wouldn't break anyway because getSetCCInverse is resilient to incorrectly assuming floating point (but not incorrectly assuming integer, which this patch fixes). This begs the question of why the extra parameter is necessary but that's a story for another day.

paulwalker-arm edited the summary of this revision. (Show Details)Mar 18 2022, 3:50 AM
This revision was landed with ongoing or failed builds.Mar 19 2022, 5:37 AM
This revision was automatically updated to reflect the committed changes.