[all-commits] [llvm/llvm-project] f05494: [SimplifyCFG] Prevent merging cbranch to cbranch i...
Valery Pykhtin via All-commits
all-commits at lists.llvm.org
Mon Nov 13 06:38:09 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: f054947c0da99ec8b3c4bb043e5225672420a313
https://github.com/llvm/llvm-project/commit/f054947c0da99ec8b3c4bb043e5225672420a313
Author: Valery Pykhtin <valery.pykhtin at gmail.com>
Date: 2023-11-13 (Mon, 13 Nov 2023)
Changed paths:
M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
A llvm/test/Transforms/SimplifyCFG/branch-cond-dont-merge.ll
Log Message:
-----------
[SimplifyCFG] Prevent merging cbranch to cbranch if the branch probability from the first to second is too low. (#69375)
AMDGPU target has faced the situation which can be illustrated with the
following testcase:
define void @dont_merge_cbranches(i32 %V) {
%divergent_cond = icmp ne i32 %V, 0
%uniform_cond = call i1 @uniform_result(i1 %divergent_cond)
br i1 %uniform_cond, label %bb2, label %exit, !prof !0
bb2:
br i1 %divergent_cond, label %bb3, label %exit
bb3:
call void @bar( )
br label %exit
exit:
ret void
}
!0 = !{!"branch_weights", i32 1, i32 100000}
SimplifyCFG merges branches on %uniform_cond and %divergent_cond which is undesirable because the first branch to bb2 is taken extremely rare and the second branch is expensive. The merged branch becomes as expensive as the second.
This patch prevents such merging if the branch to the second branch is unlikely to happen.
More information about the All-commits
mailing list