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

Missed optimization: `scmp(sext(x))` can be folded to `scmp(x)`

Open ruriww opened this issue 5 months ago • 4 comments

https://godbolt.org/z/TT1e3P1h8

Final IR:

  %_12 = tail call i32 @memcmp(ptr noundef nonnull dereferenceable(32) %x, ptr noundef nonnull dereferenceable(32) %y, i64 32)
  %0 = sext i32 %_12 to i64
  %_0 = tail call i8 @llvm.scmp.i8.i64(i64 %0, i64 0)
  ret i8 %_0

ruriww avatar Jun 09 '26 00:06 ruriww

Related:

  • https://github.com/llvm/llvm-project/pull/191182
  • https://github.com/llvm/llvm-project/pull/196847

These fold extend/trunc(scmp) rather than scmp(extend/trunc)

ruriww avatar Jun 09 '26 00:06 ruriww

Hi, I've started working on this issue. Could you please assign this issue to me?

iamaayushrivastava avatar Jun 09 '26 06:06 iamaayushrivastava

Hello. I know that iamaayushrivastava is assigned but I can try if needed and I have a PR ready.

tadeuszjt avatar Aug 25 '26 18:08 tadeuszjt

Hello. I know that iamaayushrivastava is assigned but I can try if needed and I have a PR ready.

Hello @tadeuszjt, I forgot to push the fix earlier. I’ve already pushed it now and will be adding the PR shortly. Apologies for the oversight.

iamaayushrivastava avatar Aug 26 '26 08:08 iamaayushrivastava