[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-09 Thread via cfe-commits

mikaelholmen wrote:

> Should be fixed by 
> [1b1c817](https://github.com/llvm/llvm-project/commit/1b1c81772fe50a1cb2b2adf8d8cf442c0b73602f).

I've confirmed that the instances of the problem that we saw are fixed by 
1b1c81772fe50a.
Thanks!

https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-09 Thread Nikita Popov via cfe-commits

nikic wrote:

It looks like simplifyAssocCastAssoc() is the problematic transform. It 
modifies a zext in-place without clearing poison flags.

https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-09 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Reduced test case: https://godbolt.org/z/d4ETPhbno

https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-09 Thread via cfe-commits

mikaelholmen wrote:

I think this patch causes miscompiles. Reproduce with
```opt bbi-88690.ll -passes=instcombine -S -o -```
So with this patch instcombine turns
```
@v_936 = global i16 -3276, align 1
@v_937 = global i24 0, align 1

define i16 @main() {
entry:
  %0 = load i16, ptr @v_936, align 1
  %unsclear = and i16 %0, 32767
  %resize = zext i16 %unsclear to i24
  %unsclear1 = and i24 %resize, 8388607
  store i24 %unsclear1, ptr @v_937, align 1
  ret i16 0
}
```
into
```
@v_936 = global i16 -3276, align 1
@v_937 = global i24 0, align 1

define i16 @main() {
entry:
  %0 = load i16, ptr @v_936, align 1
  %resize = zext nneg i16 %0 to i24
  store i24 %resize, ptr @v_937, align 1
  ret i16 0
}
```
I.e the and with 32767 (0x7fff) is gone and instead the zext got "nneg"?
But the value in v_936 can be, and actually _is_ negative.

[bbi-88690.ll.gz](https://github.com/llvm/llvm-project/files/13306009/bbi-88690.ll.gz)


https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-08 Thread Nikita Popov via cfe-commits

https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits