[PATCH] D94355: [SimplifyCFG] Add relative switch lookup tables

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 12 10:09:17 PST 2021


leonardchan added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5729-5743
+    Value *Load = Builder.CreateLoad(
         cast<ArrayType>(Array->getValueType())->getElementType(), GEP,
         "switch.load");
+
+    /// If relative lookup table is generated, create instructions to add
+    /// lookup table address and offset and compute the target address
+    if (IsRelative) {
----------------
We will want to use `llvm.load.relative` instead since it has some optimizations around it during instruction lowering.

Calling `llvm.load.relative(Array, Index)` should be functionally equivalent to the GEP+Load for getting the offset, then the Add back onto the array.


================
Comment at: llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll:2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -simplifycfg -switch-to-lookup=true -relative-switch-lookup-table=true -keep-loops=false -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
----------------
Could you also add the equivalent new PM-style opt invocation here, similar to what you have in `ARM/switch-to-relative-lookup-table.ll`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355



More information about the llvm-commits mailing list