[PATCH] Switch lowering: extract jump tables and bit tests before building binary tree (PR22262)

Hans Wennborg hans at chromium.org
Wed Apr 15 06:42:35 PDT 2015


Sorry for the lack of updates. I'll try to get this patch moving again.

In http://reviews.llvm.org/D8649#151108, @djasper wrote:

> Is it possible to get some idea of which bit tests LLVM is not finding with your bit tests? From your comments and IRC discussion, it feels like it should be finding more bit tests.


I have a theory. The previous code has a "number of cmps" concepts, where a single case counts as 1, and a range counts as 2, and this metric affects whether we build bit tests.

Since we can compare both single cases and ranges with a single comparison (though the range also requires a subtraction), my patch just uses the number of clusters. I'll try to confirm if that's the reason for the difference.


================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7275-7277
@@ +7274,5 @@
+    APInt Lo = Clusters[i].Low->getValue();
+    TotalCases[i] = (Hi - Lo).getLimitedValue() + 1;
+    if (i != 0)
+      TotalCases[i] += TotalCases[i - 1];
+  }
----------------
djasper wrote:
> Do I understand this correctly in that you would could something like:
> 
>   case 1:
>   case 2:
>   case 3:
>   case 4:
>   ...
>   case 10:
>     f();
>     break;
> 
> as 100% dense? I don't think this would be a good idea. Essentially, the density of a jump table should be a measure for the amount of redundancy in it.
> 
> Probably not worth addressing in this patch as it is pre-existing, but we should look into that.
Yes, that counts as 100% dense. The current code has the same problem, and you're right that we'd want to bias against building tables in this case.

However, the switch above only has one cluster, and we require 4 for a jump table. So we're not completely messing things up :-)

http://reviews.llvm.org/D8649

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list