[llvm] [SimplifyCFG] Fix the compile crash for invalid upper bound value (PR #71351)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 01:47:00 PST 2023


https://github.com/zmodem commented:

Since @nikic is the ConstantRange expert, I'd like his input here.

Please let me know if I've got this right. In the test we have:

```
%add = add nuw i32 %x, 1                        ; the UpperBound is unconfirmed
```

It seems the upper bound for `%add` would be 2^32-1. However, since the upper end of  `ConstantRange` is exclusive, it means `ConstantRange::Upper` becomes 2^32 which wraps to zero? That's pretty subtle.

Instead of checking for zero, I think this would be clearer:

```
// Check that the constant range hasn't wrapped.
if (CR.getUpper() > CR.getLower() && ...
```

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


More information about the llvm-commits mailing list