[llvm] [DAG] SelectionDAG::canCreateUndefOrPoison - Mark AVGFLOORS and AVGCE… (PR #148191)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 11 04:23:47 PDT 2025


RKSimon wrote:

You need to remove the noundef and compare the effect of freezing the result vs the inputs:
```
----------------------------------------
define i8 @src(i8 %a, i8 %b) {
#0:
  %a32 = sext i8 %a to i32
  %b32 = sext i8 %b to i32
  %and = and i32 %a32, %b32
  %xor = xor i32 %a32, %b32
  %shr = ashr i32 %xor, 1
  %res = add i32 %and, %shr
  %trunc = trunc i32 %res to i8
  %freeze = freeze i8 %trunc
  ret i8 %freeze
}
=>
define i8 @tgt(i8 %a, i8 %b) {
#0:
  %fa = freeze i8 %a
  %fb = freeze i8 %b
  %a32 = sext i8 %fa to i32
  %b32 = sext i8 %fb to i32
  %and = and i32 %a32, %b32
  %xor = xor i32 %a32, %b32
  %shr = ashr i32 %xor, 1
  %res = add i32 %and, %shr
  %trunc = trunc i32 %res to i8
  ret i8 %trunc
}
Transformation seems to be correct!
```
(if you remove either of the dst freezes it should fail)

https://github.com/llvm/llvm-project/pull/148191


More information about the llvm-commits mailing list