From patchwork Mon Aug 29 19:45:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 1110382 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7TJjvv3021927 for ; Mon, 29 Aug 2011 19:46:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754878Ab1H2Tpw (ORCPT ); Mon, 29 Aug 2011 15:45:52 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:58350 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754797Ab1H2Tpv (ORCPT ); Mon, 29 Aug 2011 15:45:51 -0400 Received: by bke11 with SMTP id 11so4446326bke.19 for ; Mon, 29 Aug 2011 12:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=BQWEOTsYQY37TeYaLKhE9QC/tRxUtZ/qO5ttFWXMhfw=; b=hPM/M47iev2hN0mVo1AMbaGIszGm4k1JwdvHhZvTvaMMqhaIS5SakR764V+Bkn6nd6 8sEA0ctvvTxOR/PKxveUaA2w0avPtfA+yCWj0g893bytx3wlV3lCE9ULyr1N7rA3INV8 F1eW188jIOXnM7wbFH6qnBrE5BaBGjoz98jX4= Received: by 10.204.137.68 with SMTP id v4mr1235635bkt.57.1314647150154; Mon, 29 Aug 2011 12:45:50 -0700 (PDT) Received: from tiger (cs181136138.pp.htv.fi [82.181.136.138]) by mx.google.com with ESMTPS id k4sm459304bkd.34.2011.08.29.12.45.46 (version=SSLv3 cipher=OTHER); Mon, 29 Aug 2011 12:45:47 -0700 (PDT) Date: Mon, 29 Aug 2011 22:45:41 +0300 (EEST) From: Pekka Enberg X-X-Sender: penberg@localhost6.localdomain6 To: Linus Torvalds cc: Jeff Garzik , linux-sparse@vger.kernel.org Subject: Re: LLVM and PSEUDO_REG/PSEUDO_PHI In-Reply-To: Message-ID: References: <4E5495C9.6050207@kernel.org> <4E55F33C.50203@kernel.org> <4E573A3E.6060104@kernel.org> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 29 Aug 2011 19:47:00 +0000 (UTC) [ Adding sparse-linux to CC. ] On Sat, 27 Aug 2011, Linus Torvalds wrote: > On Sat, Aug 27, 2011 at 2:19 AM, Pekka Enberg wrote: >> >> Looking at this: >> >> sete: >> .L0x7f188cf71c90: >>         >>        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: the generated code now looks sane: 0000000000000000 : 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 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 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; }