This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach RISCVCodeGenPrepare to optimize (zext (abs(i32 X, i1 1))).
ClosedPublic

Authored by craig.topper on Jul 22 2022, 11:48 PM.

Details

Summary

(abs(i32 X, i1 1) always produces a positive result. The 'i1 1'
means INT_MIN input produces poison. If the result is sign extended,
InstCombine will convert it to zext. This does not produce ideal
code for RISCV.

This patch reverses the zext back to sext which can be folded
into a subw or negw. Ideally we'd do this in SelectionDAG, but
we lose the INT_MIN poison flag when llvm.abs becomes ISD::ABS.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 22 2022, 11:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 11:48 PM
craig.topper requested review of this revision.Jul 22 2022, 11:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 11:48 PM
reames accepted this revision.Jul 25 2022, 8:50 AM

LGTM

llvm/test/CodeGen/RISCV/iabs.ll
697

Please, in general, just precommit tests without separate review. It makes it much easier to understand the code change being proposed.

This revision is now accepted and ready to land.Jul 25 2022, 8:50 AM
This revision was landed with ongoing or failed builds.Jul 25 2022, 9:37 AM
This revision was automatically updated to reflect the committed changes.