missed x86 optimization for flags
| Bugzilla Link | 5443 |
| Resolution | FIXED |
| Resolved on | Apr 11, 2013 00:34 |
| Version | trunk |
| OS | All |
| CC | @asl,@darkbuck |
Extended Description
X86-64 compiles this code:
define {i64, i1} @addo.apint.i64 ( i64 %left, i64 %right ) { entry: %extleft = zext i64 %left to i65 %extright = zext i64 %right to i65 %sum = add i65 %extleft, %extright %res.0 = trunc i65 %sum to i64 %overflow = and i65 %sum, -18446744073709551616 %res.1 = icmp ne i65 %overflow, 0 %final0 = insertvalue {i64, i1} undef, i64 %res.0, 0 %final1 = insertvalue {i64, i1} %final0, i1 %res.1, 1 ret {i64, i1} %final1 }
define {i64, i1} @addo.intrinsics.i64 ( i64 %left, i64 %right ) { entry: %call = call {i64, i1} @llvm.uadd.with.overflow.i64 ( i64 %left, i64 %right ) ret {i64, i1} %call }
declare {i64, i1} @llvm.uadd.with.overflow.i64 ( i64 %left, i64 %right ) nounwind readnone
to:
_addo.apint.i64: ## @addo.apint.i64 xorl %ecx, %ecx movq %rdi, %rax addq %rsi, %rax adcq $0, %rcx testb $1, %cl setne %dl ret
_addo.intrinsics.i64: ## @addo.intrinsics.i64 movq %rdi, %rax addq %rsi, %rax setb %dl ret
They should be equivalent and we're probably only a dag combine away from getting the former case to compile to the latter code.
Great! Very nice.
It's fixed in r179265. Now both functions are compiled into the same neat code.
I made a bunch of progress on this, we now get this down to:
_addo.apint.i64: ## @addo.apint.i64 movq %rdi, %rax addq %rsi, %rax sbbq %rcx, %rcx testb $1, %cl setne %dl ret
I'm done working on this for the evening.
Doing
%tmp = lshr i65 %sum, 64 %res.1 = trunc i65 %tmp to i1
rather than
%overflow = and i65 %sum, -18446744073709551616
%res.1 = icmp ne i65 %overflow, 0
gives
xorl %ecx, %ecx
movq %rdi, %rax
addq %rsi, %rax
adcq $0, %rcx
andq $1, %rcx
movb %cl, %dl
ret
which is maybe slightly better code. If it is better I guess turning the first version into this is only an additional DAG combine away :)