[PATCH] D150943: [SimplifyCFG] add nsw on BuildLookuptable LinearMap calculation

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 21 11:28:20 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6122
+    LinearOffset->getValue().sadd_ov(
+        LinearMultiplier->getValue().smul_ov(MaxIndex, MulSW), AddSW);
     if (!LinearMultiplier->isOne())
----------------
I don't think this is sufficient. Let's say we have multiplier 2 and MaxIndex is -1 (that is, full range). Then 2*-1 does not overflow, but there are still plenty of values in the range that do overflow (e.g. INT_MAX).

A possible way to properly handle this would be using ConstantRange. I think another possibility is to used ssub_ov for the `Val - PrevVal` calculation above and set NSW based on the overflow flag there.

In any case, we need additional tests to cover this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150943/new/

https://reviews.llvm.org/D150943



More information about the llvm-commits mailing list