[llvm-commits] [Patch] Use TargetTransformInfo to control switch-to-lookup table transform

Eli Friedman eli.friedman at gmail.com
Mon Oct 29 09:53:53 PDT 2012


On Mon, Oct 29, 2012 at 9:50 AM, Duncan Sands <baldrick at free.fr> wrote:
> Hi Hal,
>
>
>>>> When the switch-to-lookup tables transform landed in SimplifyCFG,
>>>>
>>>> it
>>>> was pointed out [1] that this could be inappropriate for some
>>>> targets.
>>>> Since there was no way at the time for the pass to know anything
>>>> about
>>>> the target, an awkward reverse-transform was added in
>>>> CodeGenPrepare
>>>> that turned lookup tables back into switches for some targets.
>>>>
>>>> The attached patch uses the new TargetTransformInfo to determine if
>>>> a
>>>> switch should be transformed, and removes
>>>> CodeGenPrepare::ConvertLoadToSwitch. Please take a look!
>>>
>>>
>>> personally I think it is completely wrong to have codegen concepts
>>> such as
>>> ISD::BR_JT and ISD::BRIND leaking into the IR level:
>>
>>
>> But these concepts are not leaking into the IR layer. These are contained
>> in Target (in lib/Target/TargetTransformImpl.cpp
>
>
> nope, Hans added it to Local.h, not to TargetTransformImpl.cpp.

I think you miscut the patch somehow; here's the relevant piece:

diff --git a/lib/Target/TargetTransformImpl.cpp
b/lib/Target/TargetTransformImpl.cpp
index d3823a6..f21e2f1 100644
--- a/lib/Target/TargetTransformImpl.cpp
+++ b/lib/Target/TargetTransformImpl.cpp
@@ -49,6 +49,12 @@ unsigned ScalarTargetTransformImpl::getJumpBufSize() const {
   return TLI->getJumpBufSize();
 }

+bool ScalarTargetTransformImpl::shouldBuildLookupTables() const {
+  return TLI->supportJumpTables() &&
+      (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
+       TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
+}
+
 //===----------------------------------------------------------------------===//
 //
 // Calls used by the vectorizers.

-Eli



More information about the llvm-commits mailing list