diff options
author | Pekka Enberg <penberg@kernel.org> | 2011-08-29 23:36:04 +0300 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2011-08-29 23:39:06 +0300 |
commit | 2dea6f7fb07cd18255cf1d73079638dc96bdd08b (patch) | |
tree | 0c9a70cb101eb60b70720e5082d457a6556252da | |
parent | 70b2c17c095d393a7313c0681e3d6cc58bb01147 (diff) | |
download | sparse-2dea6f7fb07cd18255cf1d73079638dc96bdd08b.tar.gz |
sparse, llvm: Fix OP_CAST to use zero-extend
Linus Torvalds explains:
On Mon, Aug 29, 2011 at 12:45 PM, Pekka Enberg <penberg@kernel.org> wrote:
> 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?
OP_CAST is always a zero-extend, OP_SCAST is a sign-extending one.
(Of course, they may be *truncating* casts too, which don't need to
generate any code on most architectures).
OP_PTRCAST should act as OP_CAST.
NOTE! The casting is dubious. We only have a single OP_FPCAST, for
example, and that's just broken. Right now "OP_FPCAST" means that the
*source* was a FP value. But if we cast *to* a FP value, it ends up
showing up as OP_[S]CAST, which is just bogus. The FPCAST should be
for any FP operation (to or from or both), and then the FPCAST logic
would have to decide how it handles it.
The FP support in general is pretty weak. The kernel doesn't do FP, I
never really cared about it.
This patch fixes comparison operator code generation. For example, this C code
int sete(int x, int y)
{
return x == y;
}
is translated as follows:
Before:
0000000000000000 <sete>:
0: 31 c9 xor %ecx,%ecx
2: 39 f7 cmp %esi,%edi
4: b8 ff ff ff ff mov $0xffffffff,%eax
9: 0f 45 c1 cmovne %ecx,%eax
c: c3 retq
After:
0000000000000000 <sete>:
0: 39 f7 cmp %esi,%edi
2: 0f 94 c0 sete %al
5: 0f b6 c0 movzbl %al,%eax
8: c3 retq
Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r-- | sparse-llvm.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index f89f7a73..a9bf679e 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; } |