6 Commits

Author SHA1 Message Date
Allen
7ec86f4d68
[SimplifyCFG] Fix the compile crash for invalid upper bound value (#71351)
Fix the crash for the last land PR70542.

Note:
For '%add = add nuw i32 %x, 1', we can only infer the LowerBound is 1,
but the UpperBound is wrapped to 0 in computeConstantRange.
so we can't assume the UpperBound is valid bound when its value is 0.

Fix https://github.com/llvm/llvm-project/issues/71329.
Reviewed By: zmodem, nikic
2023-11-09 12:33:24 +08:00
Hans Wennborg
05ed92127c Revert "Reland [SimplifyCFG] Delete the unnecessary range check for small mask operation (#70542)"
This caused https://github.com/llvm/llvm-project/issues/71329

> Fix the compile crash when the default result has no result  for
> https://github.com/llvm/llvm-project/pull/65835
>
> Fixes https://github.com/llvm/llvm-project/issues/65120
> Reviewed By: zmodem, nikic

This reverts commit 7c4180a36a905b7ed46c09df77af1b65e356f92a.
2023-11-07 10:53:22 +01:00
Allen
7c4180a36a
Reland [SimplifyCFG] Delete the unnecessary range check for small mask operation (#70542)
Fix the compile crash when the default result has no result  for
https://github.com/llvm/llvm-project/pull/65835

Fixes https://github.com/llvm/llvm-project/issues/65120
Reviewed By: zmodem, nikic
2023-11-03 09:12:29 +08:00
Allen
851338b126
Revert "[SimplifyCFG] Delete the unnecessary range check for small mask operation (#70324)
This reverts commit 5e07481d4240b5e8fd85f9b92df30849606c2af0.
2023-10-26 20:39:24 +08:00
zhongyunde 00443407
5e07481d42 [SimplifyCFG] Delete the unnecessary range check for small mask operation
When the small mask value little than 64, we can eliminate the checking
for upper limit of the range by enlarge the lookup table size to the maximum
index value. (Then the final table size grows to the next pow2 value)
```
bool f(unsigned x) {
    switch (x % 8) {
        case 0: return 1;
        case 1: return 0;
        case 2: return 0;
        case 3: return 1;
        case 4: return 1;
        case 5: return 0;
        case 6: return 1;

        // This would remove the range check: case 7: return 0;
    }
    return 0;
}
```
Use WouldFitInRegister instead of fitsInLegalInteger to support
more result type beside bool.

Fixes https://github.com/llvm/llvm-project/issues/65120
Reviewed By: zmodem, nikic, RKSimon
2023-10-26 19:01:22 +08:00
zhongyunde 00443407
925f4622dc [SimplifyCFG] Precommit tests for PR65835 2023-10-26 18:57:15 +08:00