This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][SelectionDAG] Add a hook to sign extend i32 ConstantInt operands of phis on RV64.
ClosedPublic

Authored by craig.topper on Apr 1 2022, 7:17 PM.

Details

Summary

Materializing constants on RISCV is simpler if the constant is sign
extended from i32. By default i32 constant operands of phis are
zero extended.

This patch adds a hook to allow RISCV to override this for i32. We
have an existing isSExtCheaperThanZExt, but it operates on EVT which
we don't have at these places in the code.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 1 2022, 7:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 7:17 PM
craig.topper requested review of this revision.Apr 1 2022, 7:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 7:17 PM

Makes sense to me.

jrtc27 added inline comments.Apr 2 2022, 3:56 AM
llvm/test/CodeGen/RISCV/aext-to-sext.ll
80

Also marking %c as signext (which is what the psABI gives you) would avoid the sext.w noise

frasercrmck added inline comments.Apr 4 2022, 2:26 AM
llvm/include/llvm/CodeGen/TargetLowering.h
2688

The comment about "this" constant is a little incongruous as no constant is provided. Even if RISC-V doesn't need it, I can imagine situations where targets may choose to sign-extend some specific constants and not others, so it may make sense to pass the Constant to this API.

Address review comments

luismarques added inline comments.Apr 7 2022, 3:35 PM
llvm/test/CodeGen/RISCV/aext-to-sext.ll
80

Also marking %c as signext (which is what the psABI gives you) would avoid the sext.w noise

In external conversations, I've commented that IMO we should be using signext more extensively in the RISC-V tests (e.g. default to adding it to every parameter unless it doesn't actually make sense). I didn't seem to have managed to persuade my audience but, until I see further arguments against it, I still stand by my position :)

This revision is now accepted and ready to land.Apr 11 2022, 2:25 PM
This revision was landed with ongoing or failed builds.Apr 11 2022, 2:40 PM
This revision was automatically updated to reflect the committed changes.