This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes][RISCV] Add a special case for (add X, -1) to ExpandIntRes_ADDSUB
ClosedPublic

Authored by liaolucy on Mar 22 2023, 8:56 AM.

Details

Summary

On targets without ADDCARRY or ADDE, we need to emit a separate
SETCC to determine carry from the low half to the high half.
The high half is calculated by a series of ADDs.

When RHSLo and RHSHi are -1, without this patch, we get:

Hi = (add (add LHSHi,(setult Lo, LHSLo), -1)

Where as with the patch we get:

Hi = (sub LHSHi, (seteq LHSLo, 0))

Only RHSLo is -1 we can instead do (setne Lo, 0).

Similar to gcc: https://godbolt.org/z/M83f6rz39

Diff Detail

Event Timeline

liaolucy created this revision.Mar 22 2023, 8:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 8:56 AM
liaolucy requested review of this revision.Mar 22 2023, 8:56 AM
craig.topper added inline comments.Mar 22 2023, 4:38 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
3048

This overwrites the Hi that was calculated above and is only correct if HiOps[1] is also all ones.

liaolucy updated this revision to Diff 507738.Mar 23 2023, 7:37 AM
liaolucy edited the summary of this revision. (Show Details)

Address comment.
Add Only RHSLo is -1 we can instead do (setne Lo, 0) and more testcases, like gcc: https://godbolt.org/z/M83f6rz39

This revision is now accepted and ready to land.Mar 23 2023, 1:40 PM
This revision was landed with ongoing or failed builds.Mar 23 2023, 6:45 PM
This revision was automatically updated to reflect the committed changes.