| Issue |
176086
|
| Summary |
`or disjoint` canonicalization blocks equivalent optimizations under `noundef`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mikaseianatsu
|
**First Input Program**
```
define i9 @src(i3 noundef %x) {
%sx = sext i3 %x to i9
%notx = xor i3 %x, -1
%snotx = sext i3 %notx to i9
%r = add i9 %sx, %snotx
ret i9 %r
}
```
**Second Input Program**
```
define i9 @src(i3 noundef %x) {
%sx = sext i3 %x to i9
%notx1 = or disjoint i3 %x, -1
%snotx = sext i3 %notx1 to i9
%r = add i9 %sx, %snotx
ret i9 %r
}
```
The first input program can be optimized by LLVM to the form shown below
```
define i9 @tgt(i3 noundef %x) {
ret i9 -1
}
```
However, the second is optimized to
```
define i9 @sext_sext_not_noundef(i3 noundef %x) {
%sx = sext i3 %x to i9
%r = add nsw i9 %sx, -1
ret i9 %r
}
```
This appears to be related to the poison semantics of `or disjoint`, which may prevent otherwise valid simplifications from triggering.
This suggests that `xor X, -1` canonicalizing to `or disjoint X, -1` may reduce downstream optimizability under `noundef`.
Below are the results of opt and alive2-tv of the second program
https://godbolt.org/z/fv9jv8Gb5
https://alive2.llvm.org/ce/z/LuvVtH
It is unclear whether this is an expected limitation of `or disjoint`, or a missed optimization that could be addressed.
Also, we found another example likes this issue
**Third Input Program**
```
define i32 @src(i32 noundef %0, i32 noundef %1) {
%3 = and i32 %1, %0
%4 = xor i32 %0, -1
%5 = xor i32 %1, -1
%6 = and i32 %4, %5
%7 = add i32 %3, %6
ret i32 %7
}
```
**Forth Input Program**
```
define i32 @src(i32 noundef %0, i32 noundef %1) {
%3 = and i32 %1, %0
%4 = or disjoint i32 %0, -1
%5 = xor i32 %1, -1
%6 = and i32 %4, %5
%7 = add i32 %3, %6
ret i32 %7
}
```
The third input program can be optimized by LLVM to the form shown below
```
define i32 @src3_noundef(i32 noundef %0, i32 noundef %1) {
%3 = xor i32 %1, %0
%4 = xor i32 %3, -1
ret i32 %4
}
```
However, the forth is optimized to
```
define i32 @src3_noundef(i32 noundef %0, i32 noundef %1) {
%3 = and i32 %1, %0
%4 = xor i32 %1, -1
%5 = add i32 %3, %4
ret i32 %5
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs