From: Richard Henderson <rth@twiddle.net>
To: Peter Maydell <peter.maydell@linaro.org>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] target-i386: guest variable shift by 0 provokes shift by -1
Date: Tue, 18 Mar 2014 07:20:58 -0700 [thread overview]
Message-ID: <5328564A.8060409@twiddle.net> (raw)
In-Reply-To: <CAFEAcA-i-=c9tW6jX__mB1QqdLPtEt24HisBbbv+iqY0Bsd7vw@mail.gmail.com>
On 03/18/2014 05:33 AM, Peter Maydell wrote:
> ---- 0x7fe9a5f
> 82 mov_i64 tmp1,rcx
> 83 mov_i64 tmp0,rax
> 84 movi_i64 tmp13,$0x1f
> 85 and_i64 tmp1,tmp1,tmp13
> 86 movi_i64 tmp13,$0x1
> 87 sub_i64 tmp3,tmp1,tmp13
> 88 shl_i64 tmp3,tmp0,tmp3
> 89 shl_i64 tmp0,tmp0,tmp1
> 90 ext32u_i64 rax,tmp0
> 91 movi_i64 tmp13,$0x0
> 92 mov_i64 cc_dst,tmp0
> 93 mov_i64 cc_src,tmp3
> 94 movi_i32 tmp5,$0x24
> 95 movi_i32 tmp6,$0x31
> 96 movi_i32 tmp11,$0x0
> 97 mov_i32 tmp12,tmp1
> 98 movcond_i32 cc_op,tmp12,tmp11,tmp5,tmp6,ne
>
> In this case the constant propagation code is smart
> enough to figure out that tmp1 is always zero at op 85,
> and therefore tmp3 is -1 at op 87. It then tries to use
> the shift constant of -1 in C when looking at op 88, and
> clang complains about the C undefined behaviour.
The tcg ops are fine here.
We've determined that cc_dst and cc_src are not live at the moment, since the
xor set cc_op to CC_OP_CLR which does not use them. We optimistically store
into them, and then conditionally store into cc_op itself at the end.
So the shift is undefined (even by tcg's rules), but the result is unused.
So the complaint must be within tcg/optimizer.c? We can shut up clang by
masking the shift operand while performing constant folding.
r~
next prev parent reply other threads:[~2014-03-18 14:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-18 12:33 [Qemu-devel] target-i386: guest variable shift by 0 provokes shift by -1 Peter Maydell
2014-03-18 14:20 ` Richard Henderson [this message]
2014-03-18 14:25 ` Peter Maydell
2014-03-18 14:39 ` Richard Henderson
2014-03-18 14:47 ` Peter Maydell
2014-03-18 14:52 ` Peter Maydell
2014-03-18 14:56 ` Richard Henderson
2014-03-18 15:01 ` Peter Maydell
2014-03-18 15:19 ` Richard Henderson
2014-03-18 16:34 ` Paolo Bonzini
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=5328564A.8060409@twiddle.net \
--to=rth@twiddle.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.