From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dibyendu Majumdar Subject: Re: sparse-llvm incorrect type when ealing with union type Date: Sun, 19 Mar 2017 20:48:03 +0000 Message-ID: References: <20170319153609.yykbjbbb6v4lw4xb@macpro.local> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from mail-it0-f51.google.com ([209.85.214.51]:37131 "EHLO mail-it0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752386AbdCSVWR (ORCPT ); Sun, 19 Mar 2017 17:22:17 -0400 Received: by mail-it0-f51.google.com with SMTP id g138so76403866itb.0 for ; Sun, 19 Mar 2017 14:21:49 -0700 (PDT) In-Reply-To: Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: Luc Van Oostenryck Cc: Linux-Sparse Hi Luc, On 19 March 2017 at 17:55, Dibyendu Majumdar wrote: > On 19 March 2017 at 17:15, Luc Van Oostenryck > wrote: >> On Sun, Mar 19, 2017 at 5:37 PM, Dibyendu Majumdar >> wrote: >>> On 19 March 2017 at 15:36, Luc Van Oostenryck >>> wrote: >>>> >>> I noticed that in the latest patch series for add/sub you are not >>> using GEP anymore, and there is a conversion to target type at the end >>> of a binary op. I will try out these changes and report back. >> >> Yes. It's not that the GEP was wrong but it was not enough and the more >> complete solution made this one unneeded. >> > > I have now tested the changes to binary op implementation - and I can > confirm that all my tests pass, and this appears to be a better > approach than the previous one that used the GEP instruction. > It seems that we can replace the other GEP too with pointer arithmetic. This makes LLVM output closer to the IR generated by sparse. The change required is in calc_memop_addr(): /* int type large enough to hold a pointer */ int_type = LLVMIntType(bits_in_pointer); /* IMPORTANT offset can be negative */ off = LLVMConstInt(int_type, (int) insn->offset, 0); /* convert src to the effective pointer type */ src = pseudo_to_value(fn, insn, insn->src); as = LLVMGetPointerAddressSpace(LLVMTypeOf(src)); addr_type = LLVMPointerType(insn_symbol_type(insn), as); src = value_to_ivalue(fn, src); addr = LLVMBuildAdd(fn->builder, src, off, ""); addr = LLVMBuildIntToPtr(fn->builder, addr, addr_type, ""); return addr; Regards Dibyendu