[Bug c++/93921] New: -Os generates much bigger code than -O{1,2,3,fast} for std::string::size

2020-02-25 Thread bsnoksru at cisco dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93921

Bug ID: 93921
   Summary: -Os generates much bigger code than -O{1,2,3,fast} for
std::string::size
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bsnoksru at cisco dot com
  Target Milestone: ---

Testing with the following code-fragment 

#include 
#include 

int foo() {
using namespace std::literals;
return "asdf"s.size();
}

int bar() {
using namespace std::string_view_literals;
return "asdf"sv.size();
}

using g++ from `trunk` (as reported by godbolt), with flags "--std=c++17" and
different optimiziation levels show that the string-view size gets inlined to a
constant for all relevant optimization levels, while the string-size code gets
inflated when optimizing for size.

[Bug c++/93921] -Os generates much bigger code than -O{1,2,3,fast} for std::string::size

2020-02-25 Thread bsnoksru at cisco dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93921

--- Comment #1 from Bjørnar Snoksrud  ---
Created attachment 47903
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47903&action=edit
godbolt output for -Os

[Bug c++/93921] -Os generates much bigger code than -O{1,2,3,fast} for std::string::size

2020-02-25 Thread bsnoksru at cisco dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93921

--- Comment #2 from Bjørnar Snoksrud  ---
Created attachment 47904
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47904&action=edit
godbolt output for -O3

[Bug c++/93921] -Os generates much bigger code than -O{1,2,3,fast} for std::string::size

2020-02-25 Thread bsnoksru at cisco dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93921

--- Comment #3 from Bjørnar Snoksrud  ---
Using '--std=c++20 -Os' generates minimal code.