[llvm] [AVR] Fix SETUGT during 128b -> 64b lowering (PR #182690)

Patryk Wychowaniec via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 22 10:40:45 PST 2026


Patryk27 wrote:

Ah! Alrighty, I've just shortened the description. 

For posterity, the previous version was:

---

We've got an optimization that turns `icmp ugt %x, <const>` into `icmp uge %x, <const+1>`, because the latter better matches how comparisons work in AVR (note that the comment there is wrong, though):

https://github.com/llvm/llvm-project/blob/a67bf7d796df75592a26a377420696e3c7b7993f/llvm/lib/Target/AVR/AVRISelLowering.cpp#L716

Our current implementation assumes that we never get told to do a "dumb" isel like this:

```llvm
%0 = icmp ugt i16 %x, 65535 ; always false
```

... because this would've been already optimized out - turns our that's not always true, we might be told do select such an instruction during i128->i64 lowering:

```llvm
%0 = icmp ugt i128 %x, 18446744073709551615 ; 2^64-1
```

... in which case the current code unnecessarily crashes.

This pull request changes the approach so that we apply the operator-swapping optimization only if it's applicable instead of panicking when it's not.

Closes https://github.com/llvm/llvm-project/issues/181504.

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


More information about the llvm-commits mailing list