This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][LegalizeIntegerTypes] Teach PromoteSetCCOperands not to sext i32 comparisons for RV64 if the promoted values are already zero extended.
ClosedPublic

Authored by craig.topper on Dec 30 2021, 1:25 PM.

Details

Summary

This is similar to what is done for targets that prefer zero extend
where we avoid using a zero extend if the promoted values are sign
extended.

We'll also check for zero extended operands for ugt, ult, uge, and ule when the
target prefers sign extend. This is different than preferring zero extend, where
we only check for sign bits on equality comparisons.

Diff Detail

Event Timeline

craig.topper created this revision.Dec 30 2021, 1:25 PM
craig.topper requested review of this revision.Dec 30 2021, 1:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 30 2021, 1:25 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
RKSimon added inline comments.Dec 30 2021, 2:30 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1707

Commit the LHS/RHS NFC renames?

Refactor the code to remove the switch and instead use ISD::isSignedIntSetCC and similar helpers.
Don't change the behavior of unsigned(non-equality) comparisons on targets other than RISCV.

craig.topper edited the summary of this revision. (Show Details)Dec 30 2021, 4:22 PM
RKSimon accepted this revision.Dec 31 2021, 4:48 AM

LGTM with one minor

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1710–1711

Drop the sentence about SExtOrZExtPromotedInteger as we don't appear to use it in here any longer?

This revision is now accepted and ready to land.Dec 31 2021, 4:48 AM
This revision was landed with ongoing or failed builds.Dec 31 2021, 5:29 PM
This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.Jan 4 2022, 11:18 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1753

Do we need to check isIntEqualitySetCC here? We can sign-extend the operands of unsigned comparisons if we want to.

craig.topper added inline comments.Jan 4 2022, 11:27 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1753

We don't. I just did it due to lack of test coverage and not wanting to increase compile time unnecessarily. A lot of the tests that the equality case triggers on are from Arguments having "signext". I thought it might be unlikely for a signext operand to be used by an unsigned compare. But now that I think about it, InstCombine can turn "x >= 0 && x < 10" into "x u< 10."