All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH] llvm: fix output_op_[ptr]cast()
Date: Fri, 3 Mar 2017 18:30:01 +0000	[thread overview]
Message-ID: <CACXZuxcBg1ry4d2AihkAJUX-6L-W_17HYXvja3q=2TFPGoJmNg@mail.gmail.com> (raw)
In-Reply-To: <CACXZuxd_gY9uaDHiCzq1TqRweeyp22ifWDDYZbYmjnMkGohenw@mail.gmail.com>

Perhaps we need these fixes?

https://patchwork.kernel.org/patch/8175541/

On 3 March 2017 at 18:06, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 3 March 2017 at 07:37, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>> On 3 March 2017 at 05:24, Luc Van Oostenryck
>> <luc.vanoostenryck@gmail.com> wrote:
>>> This should fox the problems of mixed types in casts.
>>> Without much testing but should be essentialy OK.
>>>
>>> CC: Dibyendu Majumdar <mobile@majumdar.org.uk>
>>> ---
>>>  sparse-llvm.c | 40 +++++++++++++++++++++++++++++++++++-----
>>>  1 file changed, 35 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/sparse-llvm.c b/sparse-llvm.c
>>> index edd0615ec..92ad26845 100644
>>> --- a/sparse-llvm.c
>>> +++ b/sparse-llvm.c
>>> @@ -763,6 +763,8 @@ static void output_op_phi(struct function *fn, struct instruction *insn)
>>>  static void output_op_ptrcast(struct function *fn, struct instruction *insn)
>>>  {
>>>         LLVMValueRef src, target;
>>> +       LLVMTypeRef dtype;
>>> +       LLVMOpcode op;
>>>         char target_name[64];
>>>
>>>         src = insn->src->priv;
>>> @@ -773,15 +775,31 @@ static void output_op_ptrcast(struct function *fn, struct instruction *insn)
>>>
>>>         assert(!symbol_is_fp_type(insn->type));
>>>
>>> -       target = LLVMBuildBitCast(fn->builder, src, insn_symbol_type(fn->module, insn), target_name);
>>> +       dtype = insn_symbol_type(fn->module, insn);
>>> +       switch (LLVMGetTypeKind(LLVMTypeOf(src))) {
>>> +       case LLVMPointerTypeKind:
>>> +               op = LLVMBitCast;
>>> +               break;
>>> +       case LLVMIntegerTypeKind:
>>> +               op = LLVMIntToPtr;
>>> +               break;
>>> +       default:
>>> +               assert(0);
>>> +       }
>>>
>>> +       target = LLVMBuildCast(fn->builder, op, src, dtype, target_name);
>>>         insn->target->priv = target;
>>>  }
>>>
>>>  static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOpcode op)
>>>  {
>>>         LLVMValueRef src, target;
>>> +       LLVMTypeRef dtype;
>>>         char target_name[64];
>>> +       unsigned int width;
>>> +
>>> +       if (is_ptr_type(insn->type))
>>> +               return output_op_ptrcast(fn, insn);
>>>
>>>         src = insn->src->priv;
>>>         if (!src)
>>> @@ -791,11 +809,23 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
>>>
>>>         assert(!symbol_is_fp_type(insn->type));
>>>
>>> -       if (insn->size < LLVMGetIntTypeWidth(LLVMTypeOf(src)))
>>> -               target = LLVMBuildTrunc(fn->builder, src, insn_symbol_type(fn->module, insn), target_name);
>>> -       else
>>> -               target = LLVMBuildCast(fn->builder, op, src, insn_symbol_type(fn->module, insn), target_name);
>>> +       dtype = insn_symbol_type(fn->module, insn);
>>> +       switch (LLVMGetTypeKind(LLVMTypeOf(src))) {
>>> +       case LLVMPointerTypeKind:
>>> +               op = LLVMPtrToInt;
>>> +               break;
>>> +       case LLVMIntegerTypeKind:
>>> +               width = LLVMGetIntTypeWidth(LLVMTypeOf(src));
>>> +               if (insn->size < width)
>>> +                       op = LLVMTrunc;
>>> +               else if (insn->size == width)
>>> +                       op = LLVMBitCast;
>>> +               break;
>>> +       default:
>>> +               assert(0);
>>> +       }
>>>
>>> +       target = LLVMBuildCast(fn->builder, op, src, dtype, target_name);
>>>         insn->target->priv = target;
>>>  }
>>>
>>
>>
>> This doesn't quite work. The problem is that in op_cast, the pointer
>> is being cast to int, but subsequent operations expect a pointer.
>>
>
> The problem occurs in this sequence:
>
>        ptrcast.64  %r26 <- (64) %r20
>        add.64      %r27 <- %r26, %r23
>        cast.64     %r28 <- (64) %r27
>        store.64    %r28 -> 16[%arg1]
>
> The last cast finds that the instruction type in an integer and does a
> cast to Integer, so that causes the store to fail as it expects a
> pointer.
>
> Question in my mind is what is the result type of an add operation
> when one of the arguments is a pointer?
>
> Regards
> Dibyendu

  reply	other threads:[~2017-03-03 18:31 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28  6:20 Sparse-LLVM issue compiling NULL pointers Dibyendu Majumdar
2017-02-28 15:09 ` Luc Van Oostenryck
2017-02-28 16:04   ` Dibyendu Majumdar
2017-02-28 16:47     ` Luc Van Oostenryck
2017-02-28 16:49     ` Dibyendu Majumdar
2017-03-02  6:48       ` Luc Van Oostenryck
2017-02-28 17:03   ` Luc Van Oostenryck
2017-02-28 17:35     ` Luc Van Oostenryck
2017-02-28 17:42       ` Dibyendu Majumdar
2017-02-28 18:08       ` Dibyendu Majumdar
2017-03-01  5:49         ` Luc Van Oostenryck
2017-03-02  7:02         ` [PATCH] llvm: fix getting type of values Luc Van Oostenryck
2017-03-01 10:58     ` Sparse-LLVM issue compiling NULL pointers Dibyendu Majumdar
2017-03-01 14:45       ` Dibyendu Majumdar
2017-03-02  5:21         ` Luc Van Oostenryck
2017-03-02  5:41           ` Dibyendu Majumdar
2017-03-02 13:56             ` Luc Van Oostenryck
2017-03-02 14:05               ` Dibyendu Majumdar
2017-03-02 16:10                 ` Luc Van Oostenryck
2017-03-02 14:33               ` Dibyendu Majumdar
2017-03-02 16:04                 ` Luc Van Oostenryck
2017-03-02 16:29                   ` Dibyendu Majumdar
2017-03-02 16:30                     ` Dibyendu Majumdar
2017-03-02 17:18                       ` Luc Van Oostenryck
2017-03-02 17:36                         ` Dibyendu Majumdar
2017-03-02 20:09                         ` Luc Van Oostenryck
2017-03-03  2:52                           ` Dibyendu Majumdar
2017-03-03  3:01                             ` Dibyendu Majumdar
2017-03-03  4:03                               ` Dibyendu Majumdar
2017-03-03  5:24                                 ` [PATCH] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-03  7:37                                   ` Dibyendu Majumdar
2017-03-03 18:06                                     ` Dibyendu Majumdar
2017-03-03 18:30                                       ` Dibyendu Majumdar [this message]
2017-03-03 19:55                                         ` Luc Van Oostenryck
2017-03-06  1:56                                           ` Christopher Li
2017-03-03 19:50                                       ` Luc Van Oostenryck
2017-03-03 19:54                                         ` Dibyendu Majumdar
2017-03-03 20:52                                           ` [PATCH] llvm: fix: do not mix pointers and floats when doing compares Luc Van Oostenryck
2017-03-03  4:16                             ` Sparse-LLVM issue compiling NULL pointers Luc Van Oostenryck
2017-03-03  4:27                             ` Luc Van Oostenryck
2017-03-03  4:38                               ` Dibyendu Majumdar
2017-03-03  7:50                                 ` Luc Van Oostenryck
2017-03-03 12:39                                   ` Dibyendu Majumdar
2017-03-02 17:03                     ` Dibyendu Majumdar
2017-03-02 17:18                       ` Dibyendu Majumdar
2017-03-02 17:43                         ` Luc Van Oostenryck
2017-03-02 18:58                           ` Dibyendu Majumdar
2017-03-02 19:34                             ` Luc Van Oostenryck
2017-03-02 17:50                       ` Luc Van Oostenryck
2017-03-02 17:57                         ` Luc Van Oostenryck
2017-03-02 18:02                           ` Dibyendu Majumdar
2017-03-03  4:21                             ` Luc Van Oostenryck
2017-03-02 17:27                   ` Luc Van Oostenryck
2017-03-02 18:41                   ` Dibyendu Majumdar
2017-03-03  5:35                     ` Luc Van Oostenryck
2017-03-02 16:39           ` Dibyendu Majumdar
2017-03-02 17:21             ` Luc Van Oostenryck

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='CACXZuxcBg1ry4d2AihkAJUX-6L-W_17HYXvja3q=2TFPGoJmNg@mail.gmail.com' \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.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 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.