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

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 17:32:32 PST 2024


Artem-B wrote:

```
def: Pat<(setule (i16 (and (trunc Int32Regs:$a), 255)), (i16 (and (trunc Int32Regs:$b), 255))),
         (SETP_u32rr Int32Regs:$a, Int32Regs:$b, CmpLS)>;
```
I agree that the pattern is wrong, though the problem here is that we pass $a and $b directly to `SETP_u32rr`.
It should've been `(SETP_u32rr BFE(Int32Regs:$a), BFE(Int32Regs:$b), CmpLS)` as in the test cases changed by the patch.

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.

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


More information about the llvm-commits mailing list