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

JunMa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 18 22:41:41 PDT 2021


junparser 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);
----------------
nikic wrote:
> 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?
yep,will add later


================
Comment at: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp:384
+    if (SIRange.getSignedMin() + (SI->getNumCases() - 1) ==
+        SIRange.getSignedMax()) {
+      createUnreachableSwitchDefault(SI, &DTU);
----------------
nikic wrote:
> 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.
you are right, i was too aggressive to relay on CVP to remove useless cases. I'll check the lower/upper bound of the cases.


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