[all-commits] [llvm/llvm-project] 36b3c2: [JumpThreading] Thread over BB with only an uncond...

XChy via All-commits all-commits at lists.llvm.org
Tue Apr 16 03:51:25 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 36b3c26451bf9a42f0b6b415993d3942bb73abdd
      https://github.com/llvm/llvm-project/commit/36b3c26451bf9a42f0b6b415993d3942bb73abdd
  Author: XChy <xxs_chy at outlook.com>
  Date:   2024-04-16 (Tue, 16 Apr 2024)

  Changed paths:
    M llvm/lib/Transforms/Utils/Local.cpp
    M llvm/test/CodeGen/AArch64/and-sink.ll
    M llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
    M llvm/test/CodeGen/Hexagon/vect/zext-v4i1.ll
    M llvm/test/Transforms/JumpThreading/pr79175.ll
    M llvm/test/Transforms/JumpThreading/select.ll
    M llvm/test/Transforms/JumpThreading/thread-prob-7.ll
    A llvm/test/Transforms/JumpThreading/uncond-no-phi.ll
    A llvm/test/Transforms/PhaseOrdering/thread-uncond-bb.ll

  Log Message:
  -----------
  [JumpThreading] Thread over BB with only an unconditional branch (#86312)

Fixes #76609
This patch does:
- relax the phis constraint in `CanRedirectPredsOfEmptyBBToSucc`
- guarantee the BB has multiple different predecessors to redirect, so
that we can handle the case without phis in BB. Without this change and
phi constraint, we may redirect the CommonPred.

The motivation is consistent with JumpThreading. We always want the
branch to jump more direct to the destination, without passing the
middle block. In this way, we can expose more other optimization
opportunities.

An obivous example proposed by @dtcxzyw is like:
```llvm
define i32 @test(...) {
entry:
   br i1 %c, label %do.end, label %if.then

if.then:                                          ; preds = %entry
   %call2 = call i32 @dummy()
   %tobool3.not = icmp eq i32 %call2, 0
   br i1 %tobool3.not, label %do.end, label %return

do.end:                                           ; preds = %entry, %if.then
   br label %return

return:                                           ; preds = %if.then, %do.end
   %retval.0 = phi i32 [ 0, %do.end ], [ %call2, %if.then ]
   ret i32 %retval.0
}
```
`entry` can directly jump to return, without passing `do.end`, and then
the if-else pattern can be simplified further:
```llvm
define i32 @test(...) {
entry:
   br i1 %c, label %return, label %if.then

if.then:                                          ; preds = %entry
   %call2 = call i32 @dummy()
   br label %return

return:                                           ; preds = %if.then
   %retval.0 = phi i32 [ 0, %entry ], [ %call2, %if.then ]
   ret i32 %retval.0
}
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list