[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
Wed Sep 15 14:05:25 PDT 2021


nikic added inline comments.


================
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
----------------
resistor wrote:
> nikic wrote:
> > resistor wrote:
> > > nikic wrote:
> > > > resistor wrote:
> > > > > nikic wrote:
> > > > > > 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`.
> > > > > Updated test to use non-zero offsets. The proposed negative test doesn't fail, and it's not clear to me that it should fail. 
> > > > This would effectively correspond to a "global1 + global2" expression, which is not a generally (or at all?) supported relocation type.
> > > The proposed test is dicey. I'm not sure that "global1 + global2" can ever be correctly marked as inbounds, in which case it's a semantically invalid input.
> > Unless LLVM can prove that it's not inbounds, it doesn't really matter. Say global2 is a weak symbol and you know that it will actually always be NULL and thus the addition is inbounds. We just use ptrtoint of globals as an easy way to produce an unfoldable expression.
> In that case we have to weaken the stripping - inbounds isn't a strong enough condition to correctness.
The condition is already "inbounds with constant offsets". While not obvious from the name, "constant offsets" here means ConstantInt offsets and already excludes constant expression GEP operands.


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