This is an archive of the discontinued LLVM Phabricator instance.

[SelectOpti][2/5] Select-to-branch base transformation
ClosedPublic

Authored by apostolakis on Mar 22 2022, 1:52 PM.

Details

Summary

This patch implements the actual transformation of selects to branches.
It includes only the base transformation without any sinking.

Depends on D120230

Diff Detail

Event Timeline

apostolakis created this revision.Mar 22 2022, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2022, 1:52 PM
apostolakis requested review of this revision.Mar 22 2022, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2022, 1:52 PM
davidxl added inline comments.
llvm/lib/CodeGen/SelectOptimize.cpp
178

The MD_prof data needs to be passed from select to the branch.

llvm/test/CodeGen/X86/select-optimize.ll
1

Add more test cases with prof meta data on select?

apostolakis added inline comments.Mar 23 2022, 8:48 AM
llvm/lib/CodeGen/SelectOptimize.cpp
178

Actually this is already done. IB.CreateCondBr (line 191) will copy the metadata (i.e., the branch weights) from the select instruction to the branch instruction.

llvm/test/CodeGen/X86/select-optimize.ll
1

Added some IR-to-IR tests that check that profile metadata are preserved. More tests with profile metadata are added in the subsequent patches.

Add some IR-to-IR tests to check profile metadata.

modimo added a subscriber: modimo.Mar 23 2022, 2:44 PM

Use only opt tests to avoid redundancy

davidxl added inline comments.Mar 24 2022, 9:52 PM
llvm/lib/CodeGen/SelectOptimize.cpp
154

Can we have a test case to demonstrate that machine sinking is actually enabled with this transformation?

229

should it skip debug stmts?

apostolakis added inline comments.Mar 25 2022, 3:14 PM
llvm/lib/CodeGen/SelectOptimize.cpp
154

This patch only includes the base transformation (as depicted in the comments here) without any sinking of eligible instructions to the newly true/false blocks of the new branch. This is why here there isn't even a new true block created and why the tests are simple. The last patch of this series (D120233) optimizes this transformation by aggressively sinking eligible instructions to the newly created true/false blocks and interleaves dependence slices to maximize ILP. In this last patch, you can see the sinking tested with several more complex tests (with the optimized transformation all eligible instructions are sunk). When lowered to assembly these instructions remain sunk. I removed the llc tests that tested assembly code since the opt tests just check the application of this pass without the effects of subsequent codegen passes that could eventually break the tests.

229

Right. If there are debug statements in between select instructions, they should be skipped and not prevent the formation of a select group. Patched the code to address this.

Skip debug/pseudo instructions when forming select group

davidxl accepted this revision.Mar 25 2022, 3:21 PM

Perhaps modify the test case to include debug statement for better coverage. Otherwise LGTM.

This revision is now accepted and ready to land.Mar 25 2022, 3:21 PM

Add debug statement in-between selects in a test case and move such debug insts just after the new phi nodes.