llvm/llvm-project

Missed optimization: (%1 <= ~%0) && (%0 > ~%1) ==> false

Open

#141.479 aperta il 26 mag 2025

Vedi su GitHub
 (7 commenti) (0 reazioni) (1 assegnatario)C++ (10.782 fork)batch import
good first issuellvm:instcombinemissed-optimization

Metriche repository

Star
 (26.378 star)
Metriche merge PR
 (Merge medio 1g 2h) (1000 PR mergiate in 30 g)

Descrizione

The following reduced IR is derived from https://github.com/Cisco-Talos/clamav/blob/6c508107355bca613ffe7b0d2a4deb7636940a87/libclamav/pe.c#L2765

Godbolt: https://godbolt.org/z/d441Gcjdr alive2 proof: https://alive2.llvm.org/ce/z/7BfGRs

define i1 @src(i32 %0, i32 %1) local_unnamed_addr #0 {
common.ret:
  %2 = xor i32 %0, -1
  %3 = icmp ule i32 %1, %2
  %4 = xor i32 %1, -1
  %5 = icmp ugt i32 %0, %4
  %common.ret.op = and i1 %3, %5
  ret i1 %common.ret.op
}

expected:

define noundef i1 @tgt(i32 %0, i32 %1) local_unnamed_addr #0 {
common.ret:
  ret i1 false
}

opt-trunk -O3 generates:

define i1 @src(i32 %0, i32 %1) local_unnamed_addr #0 {
common.ret:
  %2 = xor i32 %0, -1
  %3 = icmp ule i32 %1, %2
  %4 = xor i32 %1, -1
  %5 = icmp ugt i32 %0, %4
  %common.ret.op = and i1 %3, %5
  ret i1 %common.ret.op
}

Guida contributor