This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Improve 64-bit integer materialization for some cases.
ClosedPublic

Authored by craig.topper on Mar 17 2021, 3:06 PM.

Details

Summary

This adds a new integer materialization strategy mainly targeted
at 64-bit constants like 0xffffffff where there are 32 or more trailing
ones with leading zeros. We can materialize these by using an addi -1
and srli to restore the leading zeros. This matches what gcc does.

I haven't limited to just these cases though. The implementation
here takes the constant, shifts out all the leading zeros and
shifts ones into the LSBs, creates the new sequence, adds an srli,
and checks if this is shorter than our original strategy.

I've separated the recursive portion into a standalone function
so I could append the new strategy outside of the recursion. Since
external users are no longer using the recursive function, I've
cleaned up the external interface to return the sequence instead of
taking a vector by reference.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 17 2021, 3:06 PM
craig.topper requested review of this revision.Mar 17 2021, 3:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2021, 3:06 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
jrtc27 added inline comments.Mar 17 2021, 3:12 PM
llvm/test/CodeGen/RISCV/sadd_sat.ll
135

Hm, would be nice to not make this pattern worse

craig.topper added inline comments.Mar 17 2021, 3:13 PM
llvm/test/CodeGen/RISCV/sadd_sat.ll
124–125

This is a regression, but was suboptimal before. We have a select_cc picking between INT64_MIN and INT64_MAX. Those are only one apart with wraparound. We could just generate one constant and add/sub the result of a sltz to it to generate the other constant.

I think DAG combine would normally do that for select of constants, but the select here is created during LegalizeDAG and is turned into select_cc immediately so DAG combine never sees it.

137–138

Same here

llvm/test/CodeGen/RISCV/sadd_sat_plus.ll
132–133

And here

145–146

And here

Rebase after adding Zbt version of saturating add/sub tests.

asb accepted this revision.Apr 1 2021, 4:59 AM

LGTM, left a couple of nits on comment typos. Thanks!

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

"And example" => "An example"

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.h
28–29

Pre-existing typo you might fix while editing this: "produced" => "is produced".

This revision is now accepted and ready to land.Apr 1 2021, 4:59 AM
This revision was landed with ongoing or failed builds.Apr 1 2021, 9:15 AM
This revision was automatically updated to reflect the committed changes.