All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jeff Garzik <jeff@garzik.org>, linux-sparse@vger.kernel.org
Subject: Re: LLVM and PSEUDO_REG/PSEUDO_PHI
Date: Mon, 29 Aug 2011 22:45:41 +0300 (EEST)	[thread overview]
Message-ID: <alpine.DEB.2.00.1108292242110.24020@localhost6.localdomain6> (raw)
In-Reply-To: <CA+55aFzbfD4RDe52HCL9mfSYMzFdvP96OiK5ifkfUKNkzjJNrg@mail.gmail.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2167 bytes --]

[ Adding sparse-linux to CC. ]

On Sat, 27 Aug 2011, Linus Torvalds wrote:
> On Sat, Aug 27, 2011 at 2:19 AM, Pekka Enberg <penberg@kernel.org> wrote:
>>
>> Looking at this:
>>
>> sete:
>> .L0x7f188cf71c90:
>>        <entry-point>
>>        seteq.32    %r83 <- %arg1, %arg2
>>        cast.32     %r84 <- (8) %r83
>>        ret.32      %r84
>>
>> Why do we have "seteq.32" there but then we have a "cast.32" from %r83 which
>> is 8 bits? Isn't it linearize.c that's confused here?
>
> No, the code is correct, you misunderstand what "seteq" does.
>
> The 32 in "seteq.32" is the OPERAND WIDTH. It takes two 32-bit values
> and checks that they are equal.
>
> The OUTPUT WIDTH is "boolean". Which you changed to 8 bits (to match
> x86 semantics). So when you return an "int", you do indeed need to
> cast from 8 bits to 32 bits.
>
> There are a few ops that have different operand width from output
> width. The cast operation itself is the obvious case, and it shows its
> operand/output widths explicitly. But "setcc" is another - since the
> output is always just a boolean.

So you were obviously correct. I checked the LLVM bitcode and I was simply 
using the wrong type of cast. With this small change:

diff --git a/sparse-llvm.c b/sparse-llvm.c
index f89f7a7..a9bf679 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -607,7 +607,7 @@ static void output_op_cast(struct function *fn, struct instruction *insn)
  	if (symbol_is_fp_type(insn->type))
  		target = LLVMBuildFPCast(fn->builder, src, symbol_type(insn->type), target_name);
  	else
-		target = LLVMBuildIntCast(fn->builder, src, symbol_type(insn->type), target_name);
+		target = LLVMBuildZExt(fn->builder, src, symbol_type(insn->type), target_name);

  	insn->target->priv = target;
  }

the generated code now looks sane:

0000000000000000 <sete>:
    0:	39 f7                	cmp    %esi,%edi
    2:	0f 94 c0             	sete   %al
    5:	0f b6 c0             	movzbl %al,%eax
    8:	c3                   	retq
    9:	eb 05                	jmp    10 <setne>

However, i'm not 100% sure that's sufficient. Is OP_CAST always 
zero-extend or do we need to check for something specific here?

 			Pekka

  parent reply	other threads:[~2011-08-29 19:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4E5495C9.6050207@kernel.org>
     [not found] ` <CA+55aFwLLn30qohqJeBZLVUYWLKUnbBxnL9u+v=4Fx8TpxDQUQ@mail.gmail.com>
     [not found]   ` <4E55F33C.50203@kernel.org>
     [not found]     ` <CAOJsxLF-=mPSdKLwmc61ZRTQrLGjPTUwVw+PqabYvGKVRwh9sQ@mail.gmail.com>
     [not found]       ` <CAOJsxLFMz7fs4ySkizHk43a0fz9VKS5ReWXoJa8cy2AQ6iwRng@mail.gmail.com>
     [not found]         ` <CA+55aFywG3vBA87W2h1f=-H144MTZesEwp5jVu8ndyBfLX7Sbg@mail.gmail.com>
     [not found]           ` <alpine.DEB.2.00.1108252046090.6272@localhost6.localdomain6>
     [not found]             ` <CA+55aFxRkS4HLeW18-q+4Co7kRdiQBv4wnD=GX5ymAGigXR3MQ@mail.gmail.com>
     [not found]               ` <alpine.DEB.2.00.1108252107210.6272@localhost6.localdomain6>
     [not found]                 ` <4E58731A.7010708@garzik.org>
     [not found]                   ` <alpine.DEB.2.00.1108271104440.2570@localhost6.localdomain6>
     [not found]                     ` <4E58AE9E.1090601@garzik.org>
     [not found]                       ` <4E59478C.9000504@garzik.org>
     [not found]                         ` <alpine.DEB.2.00.1108280815530.2734@localhost6.localdomain6>
2011-08-28 10:04                           ` [PATCH] Re: LLVM and PSEUDO_REG/PSEUDO_PHI Jeff Garzik
2011-08-28 10:18                             ` Jeff Garzik
2011-08-29 14:45                               ` Pekka Enberg
2011-08-28 17:04                             ` Linus Torvalds
2011-08-28 17:52                               ` Josh Triplett
2011-08-28 18:23                                 ` Linus Torvalds
2011-08-28 19:33                                   ` Jeff Garzik
2011-08-31 12:09                                     ` Pekka Enberg
2011-08-28 19:31                               ` Jeff Garzik
2011-08-28 19:46                                 ` Linus Torvalds
2011-08-29 14:42                             ` Pekka Enberg
2011-08-29 15:14                               ` Jeff Garzik
2011-08-29 16:16                               ` Josh Triplett
     [not found]                 ` <alpine.DEB.2.00.1108252310490.22479@localhost6.localdomain6>
     [not found]                   ` <CA+55aFy3TUT=BFD+Nb9H6uDBhz427kC4tBc+ehQDs6JBggTuHQ@mail.gmail.com>
     [not found]                     ` <4E573A3E.6060104@kernel.org>
     [not found]                       ` <CA+55aFzbV0OvrtkzbjxvL1tkfF=+6xbBsyWb8XtAcK-YNeKjZw@mail.gmail.com>
     [not found]                         ` <alpine.DEB.2.00.1108271214410.14365@localhost6.localdomain6>
     [not found]                           ` <CA+55aFzbfD4RDe52HCL9mfSYMzFdvP96OiK5ifkfUKNkzjJNrg@mail.gmail.com>
2011-08-29 19:45                             ` Pekka Enberg [this message]
2011-08-29 19:52                               ` Jeff Garzik
2011-08-29 20:32                               ` Linus Torvalds
2011-08-29 20:42                                 ` Pekka Enberg

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=alpine.DEB.2.00.1108292242110.24020@localhost6.localdomain6 \
    --to=penberg@kernel.org \
    --cc=jeff@garzik.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.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.