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

Incorrect select-to-or transformation when the unselected operand may be poison

Open AIC33145 opened this issue 2 months ago • 1 comments

The following optimization changes the observable poison behavior of the program:

select i1 %c, i1 true, i1 %trunc

is transformed into:

or i1 %c, %trunc

These two forms are not equivalent when %trunc may be poison.

Source IR

define i1 @src(i1 %c, i8 noundef range(i8 0, 2) %x) {
  %trunc = trunc nsw i8 %x to i1
  %or = select i1 %c, i1 true, i1 %trunc
  ret i1 %or
}

Target IR

define i1 @tgt(i1 %c, i8 noundef range(i8 0, 2) %x) local_unnamed_addr #0 {
  %trunc = trunc nuw nsw i8 %x to i1
  %or = or i1 %c, %trunc
  ret i1 %or
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }

Alive2 Report: https://alive2.llvm.org/ce/z/qNv5-Y

Similar issue: #220487

AIC33145 avatar Sep 07 '26 07:09 AIC33145

it has been fixed by https://github.com/llvm/llvm-project/pull/220930

https://godbolt.org/z/MsMeY17zv

AIC33145 avatar Sep 07 '26 07:09 AIC33145