This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add basic support for the sifive-7-series short forward branch optimization.
ClosedPublic

Authored by craig.topper on Oct 12 2022, 2:11 PM.

Details

Summary

sifive-7-series has macrofusion support to convert a branch over
a single instruction into a conditional instruction. This can be
an improvement if the branch is hard to predict.

This patch adds support for the most basic case, a branch over a
move instruction. This is implemented as a pseudo instruction so
we can hide the control flow until all code motion passes complete.

I've disabled a recent select optimization if this feature is enabled
in the subtarget.

Related gcc patch for the same optimization https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg211045.html

Diff Detail

Event Timeline

craig.topper created this revision.Oct 12 2022, 2:11 PM
craig.topper requested review of this revision.Oct 12 2022, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 2:11 PM
craig.topper edited the summary of this revision. (Show Details)Oct 12 2022, 2:13 PM
reames added inline comments.Oct 12 2022, 2:28 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
9458–9459

I think you probably want to make the 0 and -1 arm transforms conditional too right?

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1773

Shouldn't MI be WorkingMI here?

llvm/test/CodeGen/RISCV/short-foward-branch-opt.ll
15

Are you intentionally giving me a punch list? :)

Address review comments

Rebase and qualify code in lowerSelect

reames accepted this revision.Oct 17 2022, 12:33 PM

LGTM w/comment addressed.

llvm/lib/Target/RISCV/RISCV.td
452

Fix comment please: CMOVBranchOpt does not exist upstream.

This revision is now accepted and ready to land.Oct 17 2022, 12:33 PM
This revision was landed with ongoing or failed builds.Oct 17 2022, 1:57 PM
This revision was automatically updated to reflect the committed changes.