[llvm] Add a pass to convert jump tables to switches. (PR #77709)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 03:41:53 PST 2024


nikic wrote:

> > For the small example you have, I noticed that using libstdc++ produces clean code. Is the root cause of the size increase with std::variant in libc++'s implementation?
> 
> I believe there are other patterns which will benefit from this pass.
> 
> Example: https://github.com/zeux/pugixml/blob/96aebcb8ae2062ad020186e32fd301db7c3a0c88/src/pugixml.cpp#L2745-L2761
> 
> ```
> @switch.table._ZN4pugi4impl10xml_parser10parse_treeEPcPNS_15xml_node_structEjc.1 = private unnamed_addr constant [8 x ptr] [ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_9opt_falseES2_S2_E5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_9opt_falseES2_NS0_8opt_trueEE5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_9opt_falseENS0_8opt_trueES2_E5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_9opt_falseENS0_8opt_trueES3_E5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_8opt_trueENS0_9opt_falseES3_E5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_8opt_trueENS0_9opt_falseES2_E5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_8opt_trueES2_NS0_9opt_falseEE5parseEPc, ptr @_ZN4pugi4impl19strconv_pcdata_implINS0_8opt_trueES2_S2_E5parseEPc], align 8
> 
> %1 = zext nneg i32 %or.i to i64
> %switch.gep705 = getelementptr inbounds [8 x ptr], ptr @switch.table._ZN4pugi4impl10xml_parser10parse_treeEPcPNS_15xml_node_structEjc.1, i64 0, i64 %1
> %switch.load706 = load ptr, ptr %switch.gep705, align 8
> %call455 = call noundef ptr %switch.load706(ptr noundef nonnull %spec.select)
> ```

Isn't this an example where we do the inverse transform? We start from a switch and SimplifyCFG converts it into a vtable?

https://github.com/llvm/llvm-project/pull/77709


More information about the llvm-commits mailing list