[llvm] [libc] [NVPTX] Disable incorrect peephole optimizations (PR #79920)

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 15:15:33 PST 2024


justinfargnoli wrote:

> It should've been (SETP_u32rr BFE(Int32Regs:$a), BFE(Int32Regs:$b), CmpLS) as in the test cases changed by the patch.

That makes sense! 

> Also, the example in the description seems to be invalid:
>> For example, when %a := Ox100 and %b := Ox1, setugt (i16 (and (trunc Int32Regs:$a), 255)), (i16 (and (trunc Int32Regs:$b), 255))) produces a false predicate. Whereas SETP_u32rr Int32Regs:$a, Int32Regs:$b, CmpHI will produce a true predicate.
> Translated into a more readable pseudo-code:
> ```
> a = 0x100
> b = 0x1
> pred =  ((uint16_t)(a) & 0xff) > ((uint16_t)(b) & 0xff);
> ```
> AFAICT, pred should be false here. It's not the matching part of the pattern that we need to fix, but rather the replacement.

It seems like we're on the same page. `pred` should be `false`. But, the replacement will change the code to behave like the below pseudo code. That pseudo code will set `pred` to `true`, producing an incorrect result. 

```
a = 0x100
b = 0x1
pred =  a > b;
```
---
Assuming there are no other review comments, can I submit this PR to get rid of the incorrect transformation?  


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


More information about the llvm-commits mailing list