From: Paolo Bonzini <pbonzini@redhat.com>
To: "Dmitry Vyukov" <dvyukov@google.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
KVM list <kvm@vger.kernel.org>,
llvmlinux@lists.linuxfoundation.org,
Alexander Potapenko <glider@google.com>,
andreyknvl <andreyknvl@google.com>,
Michael Davidson <md@google.com>,
Greg Hackmann <ghackmann@google.com>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: "KVM: x86: generalize guest_cpuid_has_ helpers" breaks clang
Date: Tue, 12 Sep 2017 18:03:47 +0200 [thread overview]
Message-ID: <5900628c-222c-fa71-ae11-00ce611c56dd@redhat.com> (raw)
In-Reply-To: <CACT4Y+Z7tsX-0bFUnPOpQHMrnjZvN0HX4aD5L6Xw7u4DZ_1Oqg@mail.gmail.com>
On 12/09/2017 17:54, Dmitry Vyukov wrote:
>> I guess clang still eliminates dead branches. Clang optimizer does
>> know that these are constant, it just does not allow build
>> success/failure nor runtime behavior depend on optimization level and
>> compiler version. I.e. with gcc you can get build failure with only
>> some compiler flags and/or compiler versions. Clang gives stable
>> result. But the optimizer does use constant propagation, etc during
>> optimization.
I can reproduce it:
$ cat f.c
int bad_code();
static inline void __attribute__((always_inline)) f(int x)
{
if (!__builtin_constant_p(x))
bad_code();
}
int main()
{
f(0);
f(1);
f(100);
}
$ clang --version
clang version 4.0.0 (tags/RELEASE_400/final)
$ clang f.c -O2 -c -o f.o
$ nm f.o
U bad_code
0000000000000000 T main
$ gcc f.c -O2 -c -o f.o
$ nm f.o
0000000000000000 T main
... but I don't know, it seems very weird. The purpose of
__builtin_constant_p is to be resolved only relatively late in the
optimization pipeline, and it has been like this for at least 15 years
in GCC.
The docs say what to expect:
You may use this built-in function in either a macro or an inline
function. However, if you use it in an inlined function and pass an
argument of the function as the argument to the built-in, GCC never
returns 1 when you call the inline function with a string constant or
compound literal (see Compound Literals) and does not return 1 when
you pass a constant numeric value to the inline function **unless you
specify the -O option**.
(emphasis mine).
> I've installed clang-3.9 (the closest version to yours my distribution
> gives me) and still got the same error with it. I would expect that
> 4.0 should give the same result as well... Are you sure you enabled
> KVM/intel/amd? (yes, I know you are maintaining KVM code :))
Heh, I don't know about Radim but "^Rmake" goes straight to "make
arch/x86/kvm/" for me. :)
Paolo
next prev parent reply other threads:[~2017-09-12 16:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-12 14:42 Dmitry Vyukov
2017-09-12 15:18 ` Radim Krčmář
2017-09-12 15:51 ` Dmitry Vyukov
2017-09-12 15:54 ` Dmitry Vyukov
2017-09-12 16:03 ` Paolo Bonzini [this message]
2017-09-12 16:16 ` Dmitry Vyukov
2017-09-12 16:33 ` Paolo Bonzini
2017-09-12 17:33 ` Dmitry Vyukov
2017-09-13 10:58 ` Radim Krčmář
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=5900628c-222c-fa71-ae11-00ce611c56dd@redhat.com \
--to=pbonzini@redhat.com \
--cc=andreyknvl@google.com \
--cc=david@redhat.com \
--cc=dvyukov@google.com \
--cc=ghackmann@google.com \
--cc=glider@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvmlinux@lists.linuxfoundation.org \
--cc=md@google.com \
--cc=ndesaulniers@google.com \
--cc=rkrcmar@redhat.com \
/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
all inboxes | Powered by JetHome®