llvm/llvm-project

[InstCombine] Missed optimization: fail to fold `(A >> C1) Pred C2` if `shr` is used multiple times

Open

#83.430 geöffnet am 29. Feb. 2024

Auf GitHub ansehen
 (8 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C++ (10.782 Forks)batch import
good first issuellvm:instcombinemissed-optimization

Repository-Metriken

Stars
 (26.378 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 1T 2h) (1.000 gemergte PRs in 30 T)

Beschreibung

Alive2 proof: https://alive2.llvm.org/ce/z/4JKW9d

Motivating example

define i1 @src(i32 %a){
entry:
  %div = ashr exact i32 %a, 3
  call void @use(i32 %div)
  %cmp = icmp slt i32 %div, 15
  ret i1 %cmp
}

can be folded to:

define i1 @tgt(i32 %a) {
  %div = ashr exact i32 %a, 3
  call void @use(i32 %div)
  %cmp = icmp slt i32 %a, 120
  ret i1 %cmp
}

This enables more optimizations for the other user of shr as I observe in benchmark. Unsigned case is in alive2 proof.

Real-world motivation

Signed case is derived from z3/src/sat/smt/pb_solver.cpp (after O3 pipeline). Unsigned case is derived from z3/src/tactic/core/collect_occs.cpp (after O3 pipeline). The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, email me please.

Let me know if you can confirm that it's an optimization opportunity, thanks.

Contributor Guide