llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

missed optimization during overflow computation (seto/xor)

Open KernelAddress opened this issue 9 years ago • 3 comments

Bugzilla Link 32327
Resolution FIXED
Resolved on Nov 16, 2017 06:32
Version trunk
OS Linux
CC @aemerson,@hfinkel,@RKSimon,@rotateright

Extended Description

clang version 5.0.0 (trunk 294296) Target: x86_64-unknown-linux-gnu

#include <inttypes.h> bool foo(uint32_t x, uint32_t y) { return !(((uint64_t)(x) * (uint64_t)(y)) >> 32); }

$ clang++ overflow.cc -O3 -S -o -

BB#0:

movl	%edi, %eax
mull	%esi
seto	%al
xorb	$1, %al
retq

.Lfunc_end0:

This should be:

movl	%edi, %eax
mull	%esi
setno	%al
retq

KernelAddress avatar Mar 17 '17 14:03 KernelAddress

Is there a test for this? This popped up in a real code.

Yes - see @​umulo_not_i32 in test/CodeGen/X86/overflow-intrinsic-setcc-fold.ll.

This was fixed here: https://reviews.llvm.org/rL314514

rotateright avatar Nov 16 '17 14:11 rotateright

Is there a test for this? This popped up in a real code.

KernelAddress avatar Nov 16 '17 07:11 KernelAddress

I guess it's already been fixed. Here's what I get

clang version 6.0.0 Target: x86_64-apple-darwin16.7.0 Thread model: posix

BB#0: ## %entry

pushq	%rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq	%rsp, %rbp
.cfi_def_cfa_register %rbp
movl	%edi, %eax
mull	%esi
setno	%al
popq	%rbp
retq

llvmbot avatar Nov 16 '17 06:11 llvmbot