[llvm] [SimplifyCFG] Use the unsigned case range for lookup tables when narrower (PR #221489)
Nazar Mokrynskyi via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 09:49:41 PDT 2026
================
@@ -7686,17 +7725,23 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
// TableIndex is the switch condition - TableIndexOffset if we don't
// use the condition directly
if (!UseSwitchConditionAsTableIndex) {
- // If the default is unreachable, all case values are s>= MinCaseVal. Then
- // we can try to attach nsw.
- bool MayWrap = true;
+ bool HasNUW = false;
----------------
nazar-pc wrote:
Removed.
It can't just fall through to the `nsw` reasoning below, though: `ssub_ov(MaxCaseVal, MinCaseVal)` bounds every difference over the signed range, but not over the unsigned one, where a case in the middle can overflow when neither extreme does — i4 `{1, 2, 3, 7, -8, -7}`, offset 1, case `-8` gives `-9`. (The existing `@signed_overflow2` is the same shape.)
So `nsw` is now gated on the signed range, with `@no_nsw_over_unsigned_range` covering it.
https://github.com/llvm/llvm-project/pull/221489
More information about the llvm-commits
mailing list