llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Missed optimization: (shl %0, 1) * (select %1, 2, 0) ==> %0 * (select %1, 4, 0)

Open AAAA-I opened this issue 7 months ago • 1 comments

The following reduced IR is derived from https://github.com/emscripten-core/emscripten/blob/d984d060ea4d89ea119a3070f09b1b29d9e3b9a4/system/lib/mimalloc/src/arena.c#L976

Godbolt: https://godbolt.org/z/rTGs6v361 alive2 proof: https://alive2.llvm.org/ce/z/FDPpFg

define noundef i64 @mi_manage_os_memory(i64 %0, i1 %1) {
  %3 = select i1 %1, i64 2, i64 0
  %4 = shl i64 %0, 1
  %5 = mul i64 %4, %3
  ret i64 %5
}

expected:

define noundef i64 @tgt(i64 %0, i1 %1) {
  %3 = select i1 %1, i64 4, i64 0
  %5 = mul i64 %0, %3
  ret i64 %5
}

AAAA-I avatar Apr 08 '26 04:04 AAAA-I

I would like to work on this issue

FathimaHaris avatar Apr 08 '26 05:04 FathimaHaris