[PATCH] D109565: Teach SimplifyCFG to fold switches into lookup tables in more cases.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 11 12:14:28 PDT 2021


nikic added inline comments.


================
Comment at: llvm/test/Transforms/SimplifyCFG/switch-to-lookup-bitcast.ll:3
+; RUN: opt -simplifycfg --switch-to-lookup -S < %s | FileCheck %s
+target triple = "x86_64-unknown-linux-gnu"
+
----------------
This target triple either needs to be dropped (if the test works without it), or the test should be moved in to the X86 subdirectory.


================
Comment at: llvm/test/Transforms/SimplifyCFG/switch-to-lookup-bitcast.ll:16
+ at alloc35 = private unnamed_addr constant <{ [1 x i8] }> <{ [1 x i8] c"B" }>, align 1
+ at alloc36 = private unnamed_addr constant <{ [1 x i8] }> <{ [1 x i8] c"A" }>, align 1
+
----------------
It would be good to reduce the number of switch cases in this test -- we probably don't need 12 to produce a lookup table.


================
Comment at: llvm/test/Transforms/SimplifyCFG/switch-to-lookup-gep.ll:80
+bb14:
+  %.sroa.0.0 = phi [0 x i8]* [ getelementptr inbounds ([0 x i8], [0 x i8]* bitcast (<{ [1 x i8] }>* @alloc25 to [0 x i8]*), i32 0), %bb1 ], [ bitcast (<{ [1 x i8] }>* @alloc26 to [0 x i8]*), %bb13 ], [ bitcast (<{ [1 x i8] }>* @alloc27 to [0 x i8]*), %bb12 ], [ bitcast (<{ [1 x i8] }>* @alloc28 to [0 x i8]*), %bb11 ], [ bitcast (<{ [1 x i8] }>* @alloc29 to [0 x i8]*), %bb10 ], [ bitcast (<{ [1 x i8] }>* @alloc30 to [0 x i8]*), %bb9 ], [ bitcast (<{ [1 x i8] }>* @alloc31 to [0 x i8]*), %bb8 ], [ bitcast (<{ [1 x i8] }>* @alloc32 to [0 x i8]*), %bb7 ], [ bitcast (<{ [1 x i8] }>* @alloc33 to [0 x i8]*), %bb6 ], [ bitcast (<{ [1 x i8] }>* @alloc34 to [0 x i8]*), %bb5 ], [ bitcast (<{ [1 x i8] }>* @alloc35 to [0 x i8]*), %bb4 ], [ bitcast (<{ [1 x i8] }>* @alloc36 to [0 x i8]*), %start ]
+  %1 = insertvalue { [0 x i8]*, i64 } undef, [0 x i8]* %.sroa.0.0, 0
----------------
This only tests a GEP with a zero offset, which is a degenerate case. It would be better to test a non-zero offset.

We could also have a negative test that no lookup table is created if a GEP index is not a constant integer (but rather something like `ptrtoint i8* @g to i64`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109565



More information about the llvm-commits mailing list