llvm/llvm-project

Failure to recognise unnecessary sext for add+cmp

Open

#130,088 建立於 2025年3月6日

在 GitHub 查看
 (23 留言) (0 反應) (1 負責人)C++ (10,782 fork)batch import
good first issuellvm:instcombinemissed-optimization

倉庫指標

Star
 (26,378 star)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

Pulled out #76524 - we fail to recognize that extension is unnecessary and that the trunc is nsw

define i8 @src(i16 noundef %x) {
entry:
  %conv = sext i16 noundef %x to i128
  %add = add i128 %conv, 128
  %or.cond.i = icmp ult i128 %add, 256
  assume i1 %or.cond.i
  %conv1 = trunc i16 noundef %x to i8
  ret i8 %conv1
}
=>
define i8 @tgt(i16 noundef %x) {
entry:
  %add = add i16 noundef %x, 128
  %or.cond.i = icmp ult i16 %add, 256
  assume i1 %or.cond.i
  %conv1 = trunc nsw i16 noundef %x to i8
  ret i8 %conv1
}
Transformation seems to be correct!

https://alive2.llvm.org/ce/z/epn8hd

貢獻者指南