This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach constant materialization that it can use zext.w at the end with Zba to reduce number of instructions.
ClosedPublic

Authored by craig.topper on Jul 6 2021, 1:23 PM.

Details

Summary

If the upper 32 bits are zero and bit 31 is set, we might be able to
use zext.w to fill in the zeros after using an lui and/or addi.

Most of this patch is plumbing the subtarget features into the constant
materialization.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 6 2021, 1:23 PM
craig.topper requested review of this revision.Jul 6 2021, 1:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2021, 1:23 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
luismarques accepted this revision.Jul 16 2021, 3:44 AM

LGTM. Thanks!

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
87

Was this undefined behavior (shifting into the sign bit)? Thanks for fixing it :)

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
435–440

We might have more of these elsewhere, where we are getting the STI from the MF when we can get it more directly.

This revision is now accepted and ready to land.Jul 16 2021, 3:44 AM
craig.topper added inline comments.Jul 16 2021, 9:21 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
87

Stealing the text from the code that instruments for UBSan.

// In C99, we are not permitted to shift a 1 bit into the sign bit.                                                                                                                                                            
// Under C++11's rules, shifting a 1 bit into the sign bit is                                                                                                                                                                  
// OK, but shifting a 1 bit out of it is not. (C89 and C++03 don't                                                                                                                                                             
// define signed left shifts, so we use the C99 and C++11 rules there).