[LLVMdev] llvm-gcc miscompilation or it's the gcc's rule?

Chris Lattner sabre at nondot.org
Sun Jan 13 22:44:05 PST 2008


On Jan 13, 2008, at 10:35 PM, Rob Barris wrote:
> I don't think C has a way to express 32b x 32b -> 64b multiply, even
> though there is (on x86 anyway) a hardware instruction that does it.
>
> The type of your expression (x * y) is still uint32_t.  The implicit
> type coercion up to uint64_t as part of the return statement doesn't
> change this.

Right. llvm-gcc and GCC are correct.  If you want this, use:

uint64_t mul(uint32_t x, uint32_t y) {
  return (uint64_t )x * y;
}

Your code generator should handle optimizing this to the simple  
instruction if your target has an instruction to do this.  For  
example, the X86 backend produces:

_mul:
	movl	8(%esp), %eax
	mull	4(%esp)
	ret

-Chris



More information about the llvm-dev mailing list