Yeah, years ago, the compiler did the right thing through a combination of jump threading and simple redundancy elimination. StringSwitch does a first character specialization IIRC. -Chris> On Oct 28, 2020, at 9:01 PM, Stephen Checkoway via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > >> On Oct 28, 2020, at 14:09, Paul C. Anagnostopoulos via llvm-dev <llvm-dev at lists.llvm.org> wrote: >> >> StringSwitch just uses a series of Case functions that compare the target against each case string. Once the target is matched, the remaining Case functions bypass the comparison. One way or the other, it goes through all the Case's. I don't think there is any way to optimize this. Does anyone know if the compiler does something clever? > > Hi Paul, > > This has come up on the list before [1]. The suggestion at the end of that thread was to look at the optimized code produced by the compiler [2]. > > Cheers, > > Steve > > 1. http://lists.llvm.org/pipermail/llvm-dev/2016-February/095075.html > 2. http://lists.llvm.org/pipermail/llvm-dev/2016-February/095265.html > > -- > Stephen Checkoway > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Paul C. Anagnostopoulos via llvm-dev
2020-Oct-29 18:48 UTC
[llvm-dev] StringSwitch efficiency
Excellent. Then I shall not concern myself with the efficiency of StringSwitch. At 10/29/2020 02:28 PM, Chris Lattner wrote:>Yeah, years ago, the compiler did the right thing through a combination of jump threading and simple redundancy elimination. StringSwitch does a first character specialization IIRC. > >-Chris
This may still need a measurement. StringSwitch takes a StringRef (const char *Data + size_t Length). The compiler cannot arbitrarily reference Data[i] if i >= Length. It can do specialization but it needs to know the valid range. On Thu, Oct 29, 2020 at 11:53 AM Paul C. Anagnostopoulos via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Excellent. Then I shall not concern myself with the efficiency of StringSwitch. > > At 10/29/2020 02:28 PM, Chris Lattner wrote: > >Yeah, years ago, the compiler did the right thing through a combination of jump threading and simple redundancy elimination. StringSwitch does a first character specialization IIRC. > > > >-Chris > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- 宋方睿