public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "balakrishnan.erode at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53792] [C++11] improving compiler-time constexpr evaluation
Date: Wed, 06 May 2015 15:03:00 -0000	[thread overview]
Message-ID: <bug-53792-4-cTi1HnMpma@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-53792-4@http.gcc.gnu.org/bugzilla/>

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

Balakrishnan B <balakrishnan.erode at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |balakrishnan.erode at gmail dot co
                   |                            |m

--- Comment #8 from Balakrishnan B <balakrishnan.erode at gmail dot com> ---
Another testcase with c++14 extended constexpr (i.e supports loops and more
than one statement).

Code:

template<class T>
void sink(T);

constexpr unsigned foo(){
  unsigned  i = 1;
  while((i<<1) > i){
    i = i<<1;
  }
  return i;
}
template<unsigned i>
  struct Foo
        {
        };

void bar(){
  sink(foo());
  sink(Foo<foo()>{});
}

Assembly for bar: 
clang3.5.1 -O3 -std=c++14
bar():                                # @bar()
        pushq   %rax
        movl    $-2147483648, %edi      # imm = 0xFFFFFFFF80000000
        callq   void sink<unsigned int>(unsigned int)
        popq    %rax
        jmp     void sink<Foo<2147483648u> >(Foo<2147483648u>) # TAILCALL

gcc5.1.0 -O3 -std=c++14
bar():
        movl    $32, %eax
        movl    $1, %edi
        jmp     .L2
.L3:
        movl    %edx, %edi
.L2:
        subl    $1, %eax
        leal    (%rdi,%rdi), %edx
        jne     .L3
        subq    $8, %rsp
        call    void sink<unsigned int>(unsigned int)
        subq    $8, %rsp
        pushq   $0
        call    void sink<Foo<2147483648u> >(Foo<2147483648u>)
        addq    $24, %rsp
        ret

Live demo: http://goo.gl/b56Q5k


      parent reply	other threads:[~2015-05-06 15:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-28  6:59 [Bug c++/53792] New: [C++11][constexpr] " vincenzo.innocente at cern dot ch
2012-06-28  9:34 ` [Bug c++/53792] " rguenth at gcc dot gnu.org
2012-06-28 11:08 ` vincenzo.innocente at cern dot ch
2012-07-19 14:28 ` jason at gcc dot gnu.org
2012-07-27 10:48 ` vincenzo.innocente at cern dot ch
2012-07-27 15:06 ` jason at redhat dot com
2012-08-08 11:18 ` giulio.eulisse at cern dot ch
2012-08-08 18:19 ` paolo.carlini at oracle dot com
2015-05-06 15:03 ` balakrishnan.erode at gmail dot com [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53792-4-cTi1HnMpma@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).