[llvm] [InstCombine] Convert load from LUT into a select (PR #98339)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 11:56:29 PDT 2024
erikdesjardins wrote:
> Miscompilation with undef: [alive2.llvm.org/ce/z/JL6br](https://alive2.llvm.org/ce/z/JL6br)_
>
> ```
> @.str = constant [2 x i8] [i8 1, i8 undef], align 1
>
> define i32 @src(i64 %x) {
> entry:
> %arrayidx = getelementptr [2 x i8], ptr @.str, i64 0, i64 %x
> %0 = load i8, ptr %arrayidx, align 1
> %conv = zext i8 %0 to i32
> ret i32 %conv
> }
>
> define i32 @tgt(i64 %x) {
> entry:
> %cond = icmp eq i64 %x, 0
> %conv = select i1 %cond, i32 1, i32 undef
> ret i32 %conv
> }
> ```
Hmm, I would expect this transform to generate
```
define i32 @tgt(i64 %x) {
entry:
%cond = icmp eq i64 %x, 0
%conv = select i1 %cond, i8 1, i8 undef
%zext = zext i8 %conv to i32
ret i32 %zext
}
```
which is valid (https://alive2.llvm.org/ce/z/ewQnvE).
Is there some existing bad transform (folding zext into select arms) which caused that miscompile?
https://github.com/llvm/llvm-project/pull/98339
More information about the llvm-commits
mailing list