Hi Chris,> Why not define an "add with overflow" intrinsic that returns its value and > overflow bit as an i1?what's the point? We have this today with apint codegen (if you turn on LegalizeTypes). For example, this function define i1 @cc(i32 %x, i32 %y) { %xx = zext i32 %x to i33 %yy = zext i32 %y to i33 %s = add i33 %xx, %yy %tmp = lshr i33 %s, 32 %b = trunc i33 %tmp to i1 ret i1 %b } codegens (on x86-32) to cc: xorl %eax, %eax movl 4(%esp), %ecx addl 8(%esp), %ecx adcl $0, %eax andl $1, %eax ret which uses the condition code as desired. Pity about the redundant andl $1, %eax! Ciao, Duncan.
On Wed, 26 Mar 2008, Duncan Sands wrote:> Hi Chris, > >> Why not define an "add with overflow" intrinsic that returns its value and >> overflow bit as an i1? > > what's the point? We have this today with apint codegen (if you turn on > LegalizeTypes). For example, this functionThe desired code is something like: foo: addl %eax, %ecx jo overflow_happened use(%ecx) etc. -Chris> define i1 @cc(i32 %x, i32 %y) { > %xx = zext i32 %x to i33 > %yy = zext i32 %y to i33 > %s = add i33 %xx, %yy > %tmp = lshr i33 %s, 32 > %b = trunc i33 %tmp to i1 > ret i1 %b > } > > codegens (on x86-32) to > > cc: > xorl %eax, %eax > movl 4(%esp), %ecx > addl 8(%esp), %ecx > adcl $0, %eax > andl $1, %eax > ret > > which uses the condition code as desired. Pity about the > redundant andl $1, %eax! > > Ciao, > > Duncan. >-Chris -- http://nondot.org/sabre/ http://llvm.org/
Hi Chris,> > what's the point? We have this today with apint codegen (if you turn on > > LegalizeTypes). For example, this function > > The desired code is something like: > > foo: > addl %eax, %ecx > jo overflow_happened > use(%ecx)how's an intrinsic going to help with this? Also, is there any chance of codegen being capable one day of combining carry arithmetic coming from apint and the appropriate conditional branch into a "jo"? Ciao, Duncan.