public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95769] New: Constant expression in inline function not optimized
@ 2020-06-19 15:33 gcc at mailinator dot com
  2020-06-19 15:38 ` [Bug tree-optimization/95769] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc at mailinator dot com @ 2020-06-19 15:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95769

            Bug ID: 95769
           Summary: Constant expression in inline function not optimized
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at mailinator dot com
  Target Milestone: ---

Godbolt link: https://godbolt.org/z/Kimna8

Code:

```
int constexpr expensive_function(int x){
    int result{};
    while(x!=1){
        x=x%2!=0 ? x*3+1 : x/2;
        result++;
    }
    return result;
}

int constexpr other_function(int a, int b){
    return a*expensive_function(b);
}

int f_(int x){
    return other_function(x, 1000);
}

int g(int x){
    return x*expensive_function(1000);
}
```

The function `g` is optimized so `expensive_function(1000)` is evaluated at
compile time. The function `f` isn't.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-22  7:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-19 15:33 [Bug tree-optimization/95769] New: Constant expression in inline function not optimized gcc at mailinator dot com
2020-06-19 15:38 ` [Bug tree-optimization/95769] " jakub at gcc dot gnu.org
2020-06-19 15:45 ` gcc at mailinator dot com
2020-06-19 15:50 ` jakub at gcc dot gnu.org
2020-06-19 15:54 ` jakub at gcc dot gnu.org
2020-06-22  7:45 ` [Bug ipa/95769] " jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).