Summary: | Function pointer imposes an optimization barrier | ||
---|---|---|---|
Product: | gcc | Reporter: | Antony Polukhin <antoshkka> |
Component: | middle-end | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | NEW --- | ||
Severity: | normal | CC: | antoshkka, dimhen, falemagn, mail, msebor |
Priority: | P3 | Keywords: | missed-optimization |
Version: | 9.0 | ||
Target Milestone: | --- | ||
See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80603 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93411 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78113 |
||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2020-01-24 00:00:00 |
Description
Antony Polukhin
2018-08-10 12:42:44 UTC
Making `visitors` a `static constexpr` turns the output to almost the same as Clang produces for this code (except an unnecessary mov). Some of our projects make heavy use of std::variant and we are beginning to notice a discrepancy in performance between GCC and Clang, specifically due to the lack of this optimization. Is anyone going to take a look at this, or should we take the time to upload a patch somewhere? Thank you I'll confirm this but I'm not sure if the problem is substantively different than something as simple as the following C program where GCC doesn't fold the array reference to zero. Even declaring the array at file scope doesn't help. (I'm pretty sure there is a report of this optimization opportunity somewhere in Bugzilla.) $ cat u.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout u.c int f (int i) { const int a[] = { 0, 0, 0 }; return a[i]; // should be folded to return 0; } ;; Function f (f, funcdef_no=0, decl_uid=1930, cgraph_uid=1, symbol_order=0) f (int i) { const int a[3]; int _6; <bb 2> [local count: 1073741824]: MEM <unsigned long> [(int *)&a] = 0; a[2] = 0; _6 = a[i_5(D)]; a ={v} {CLOBBER}; return _6; } See also pr80603 and its duplicate pr93411 that I raised for the missing optimization in comment #3. |