This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Optimize (select Cond, X, 0) --> and (sext Cond), X
Needs ReviewPublic

Authored by StephenFan on Mar 21 2022, 8:51 PM.

Details

Summary

Add target dependent DAG combine for select node. The optimization is transform
select Cond, X, 0 to and (sext Cond), X. For RISCV, this optimization can decrease
code size. Other Arch(like X86) seems not. So I didn't add this optimization to generic
DAG Combine.

Diff Detail

Event Timeline

StephenFan created this revision.Mar 21 2022, 8:51 PM
Herald added a project: Restricted Project. · View Herald Transcript
StephenFan requested review of this revision.Mar 21 2022, 8:51 PM

Are you sure this is a code size win with RVC? Also much less likely to be macro-op fused; conditional branch followed by a move is one of the things you can easily fuse, and some cores already implement predicated execution for short forward conditional branches.

craig.topper added inline comments.Mar 21 2022, 9:49 PM
llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
21

This is clearly worse