[PATCH] D106056: [CVP] processSwitch: Remove default case when switch cover all possible values.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 16 10:02:05 PDT 2021


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp:381
+
+    // Try to simplify default case as unreachable
+    const ConstantRange SIRange = LVI->getConstantRange(SI->getCondition(), SI);
----------------
What about the case where the default already has an unreachable terminator? Aren't you going to perform a no-op transform in that case?


================
Comment at: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp:384
+    if (SIRange.getSignedMin() + (SI->getNumCases() - 1) ==
+        SIRange.getSignedMax()) {
+      createUnreachableSwitchDefault(SI, &DTU);
----------------
This condition is wrong. Let's say your switch argument has range [0, 9] and your switch cases have range [10, 19]. The input range and the switch cases have the same size, but they don't have the same values and default destination is not dead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106056



More information about the llvm-commits mailing list