* [PATCH] sparse, llvm: convert the condition of branch/select to bool
@ 2012-08-19 14:52 Jonathan Neuschäfer
2012-08-19 15:13 ` Pekka Enberg
2012-08-19 16:50 ` Jeff Garzik
0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Neuschäfer @ 2012-08-19 14:52 UTC (permalink / raw)
To: linux-sparse
Cc: Jonathan Neuschäfer, Pekka Enberg, Christopher Li,
Jeff Garzik, Linus Torvalds
LLVM expects the first argument of "br" and "select" to be of type i1,
so add an "icmp ne <srcty> %src, 0" for other types.
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---
sparse-llvm.c | 13 +++++++++++--
validation/backend/int-cond.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 2 deletions(-)
create mode 100644 validation/backend/int-cond.c
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 213d42d..e4929e9 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -650,10 +650,19 @@ static void output_op_store(struct function *fn, struct instruction *insn)
insn->target->priv = target;
}
+static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value)
+{
+ if (LLVMTypeOf(value) != LLVMInt1Type())
+ value = LLVMBuildIsNotNull(fn->builder, value, "cond");
+
+ return value;
+}
+
static void output_op_br(struct function *fn, struct instruction *br)
{
if (br->cond) {
- LLVMValueRef cond = pseudo_to_value(fn, br, br->cond);
+ LLVMValueRef cond = bool_value(fn,
+ pseudo_to_value(fn, br, br->cond));
LLVMBuildCondBr(fn->builder, cond,
br->bb_true->priv,
@@ -668,7 +677,7 @@ static void output_op_sel(struct function *fn, struct instruction *insn)
{
LLVMValueRef target, src1, src2, src3;
- src1 = pseudo_to_value(fn, insn, insn->src1);
+ src1 = bool_value(fn, pseudo_to_value(fn, insn, insn->src1));
src2 = pseudo_to_value(fn, insn, insn->src2);
src3 = pseudo_to_value(fn, insn, insn->src3);
diff --git a/validation/backend/int-cond.c b/validation/backend/int-cond.c
new file mode 100644
index 0000000..48b25a7
--- /dev/null
+++ b/validation/backend/int-cond.c
@@ -0,0 +1,30 @@
+static long foo(long a, long b, long c)
+{
+ return a? b:c;
+}
+
+static long foo_bool(_Bool a, long b, long c)
+{
+ return a? b:c;
+}
+
+static long bar(long a, long b, long c)
+{
+ if (a)
+ return b;
+ else
+ return b + c;
+}
+
+static long bar_bool(_Bool a, long b, long c)
+{
+ if (a)
+ return b;
+ else
+ return b + c;
+}
+
+/*
+ * check-name: Non-bool condition values in branch/select
+ * check-command: ./sparsec -c $file -o tmp.o
+ */
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sparse, llvm: convert the condition of branch/select to bool
2012-08-19 14:52 [PATCH] sparse, llvm: convert the condition of branch/select to bool Jonathan Neuschäfer
@ 2012-08-19 15:13 ` Pekka Enberg
2012-08-19 16:50 ` Jeff Garzik
1 sibling, 0 replies; 4+ messages in thread
From: Pekka Enberg @ 2012-08-19 15:13 UTC (permalink / raw)
To: Jonathan Neuschäfer
Cc: linux-sparse, Christopher Li, Jeff Garzik, Linus Torvalds
On Sun, Aug 19, 2012 at 5:52 PM, Jonathan Neuschäfer
<j.neuschaefer@gmx.net> wrote:
> LLVM expects the first argument of "br" and "select" to be of type i1,
> so add an "icmp ne <srcty> %src, 0" for other types.
>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: Christopher Li <sparse@chrisli.org>
> Cc: Jeff Garzik <jgarzik@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Applied, thanks Jonathan!
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sparse, llvm: convert the condition of branch/select to bool
2012-08-19 14:52 [PATCH] sparse, llvm: convert the condition of branch/select to bool Jonathan Neuschäfer
2012-08-19 15:13 ` Pekka Enberg
@ 2012-08-19 16:50 ` Jeff Garzik
2012-08-19 17:02 ` Pekka Enberg
1 sibling, 1 reply; 4+ messages in thread
From: Jeff Garzik @ 2012-08-19 16:50 UTC (permalink / raw)
To: Pekka Enberg
Cc: Jonathan Neuschäfer, linux-sparse, Christopher Li,
Jeff Garzik, Linus Torvalds
On 08/19/2012 10:52 AM, Jonathan Neuschäfer wrote:
> LLVM expects the first argument of "br" and "select" to be of type i1,
> so add an "icmp ne <srcty> %src, 0" for other types.
>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: Christopher Li <sparse@chrisli.org>
> Cc: Jeff Garzik <jgarzik@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> ---
> sparse-llvm.c | 13 +++++++++++--
> validation/backend/int-cond.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 41 insertions(+), 2 deletions(-)
> create mode 100644 validation/backend/int-cond.c
Nice -- and I wonder if this fixes the loop bug Pekka noted in private
email on 2011/11/23?
Pekka, do you mind if I forward your email to the list?
Jeff
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sparse, llvm: convert the condition of branch/select to bool
2012-08-19 16:50 ` Jeff Garzik
@ 2012-08-19 17:02 ` Pekka Enberg
0 siblings, 0 replies; 4+ messages in thread
From: Pekka Enberg @ 2012-08-19 17:02 UTC (permalink / raw)
To: Jeff Garzik
Cc: Jonathan Neuschäfer, linux-sparse, Christopher Li,
Jeff Garzik, Linus Torvalds
On Sun, Aug 19, 2012 at 7:50 PM, Jeff Garzik <jgarzik@pobox.com> wrote:
> On 08/19/2012 10:52 AM, Jonathan Neuschäfer wrote:
>>
>> LLVM expects the first argument of "br" and "select" to be of type i1,
>> so add an "icmp ne <srcty> %src, 0" for other types.
>>
>> Cc: Pekka Enberg <penberg@kernel.org>
>> Cc: Christopher Li <sparse@chrisli.org>
>> Cc: Jeff Garzik <jgarzik@redhat.com>
>> Cc: Linus Torvalds <torvalds@linux-foundation.org>
>> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>> ---
>> sparse-llvm.c | 13 +++++++++++--
>> validation/backend/int-cond.c | 30 ++++++++++++++++++++++++++++++
>> 2 files changed, 41 insertions(+), 2 deletions(-)
>> create mode 100644 validation/backend/int-cond.c
>
>
> Nice -- and I wonder if this fixes the loop bug Pekka noted in private email
> on 2011/11/23?
>
> Pekka, do you mind if I forward your email to the list?
No, not at all. Feel free to forward it.
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-19 17:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-19 14:52 [PATCH] sparse, llvm: convert the condition of branch/select to bool Jonathan Neuschäfer
2012-08-19 15:13 ` Pekka Enberg
2012-08-19 16:50 ` Jeff Garzik
2012-08-19 17:02 ` Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).