Add some notes about better flag handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41808 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-09-10 21:43:18 +00:00
parent 61c5ff460b
commit bf8ae84a21
3 changed files with 101 additions and 1 deletions

View File

@ -528,3 +528,48 @@ _foo:
This apparently occurs in real code.
//===---------------------------------------------------------------------===//
This:
#include <algorithm>
std::pair<unsigned, bool> full_add(unsigned a, unsigned b)
{ return std::make_pair(a + b, a + b < a); }
bool no_overflow(unsigned a, unsigned b)
{ return !full_add(a, b).second; }
Should compile to:
_Z8full_addjj:
adds r2, r1, r2
movcc r1, #0
movcs r1, #1
str r2, [r0, #0]
strb r1, [r0, #4]
mov pc, lr
_Z11no_overflowjj:
cmn r0, r1
movcs r0, #0
movcc r0, #1
mov pc, lr
not:
__Z8full_addjj:
add r3, r2, r1
str r3, [r0]
mov r2, #1
mov r12, #0
cmp r3, r1
movlo r12, r2
str r12, [r0, #+4]
bx lr
__Z11no_overflowjj:
add r3, r1, r0
mov r2, #1
mov r1, #0
cmp r3, r0
movhs r1, r2
mov r0, r1
bx lr
//===---------------------------------------------------------------------===//

View File

@ -677,5 +677,33 @@ LBB1_1: ;bb
cmplwi cr0, r6, 33920
bne cr0, LBB1_1
===-------------------------------------------------------------------------===
//===---------------------------------------------------------------------===//
This:
#include <algorithm>
inline std::pair<unsigned, bool> full_add(unsigned a, unsigned b)
{ return std::make_pair(a + b, a + b < a); }
bool no_overflow(unsigned a, unsigned b)
{ return !full_add(a, b).second; }
Should compile to:
__Z11no_overflowjj:
add r4,r3,r4
subfc r3,r3,r4
li r3,0
adde r3,r3,r3
blr
(or better) not:
__Z11no_overflowjj:
add r2, r4, r3
cmplw cr7, r2, r3
mfcr r2
rlwinm r2, r2, 29, 31, 31
xori r3, r2, 1
blr
//===---------------------------------------------------------------------===//

View File

@ -1178,3 +1178,30 @@ We should sink the load into xmm3 into the LBB1_2 block. This should
be pretty easy, and will nuke all the copies.
//===---------------------------------------------------------------------===//
This:
#include <algorithm>
inline std::pair<unsigned, bool> full_add(unsigned a, unsigned b)
{ return std::make_pair(a + b, a + b < a); }
bool no_overflow(unsigned a, unsigned b)
{ return !full_add(a, b).second; }
Should compile to:
_Z11no_overflowjj:
addl %edi, %esi
setae %al
ret
on x86-64, not:
__Z11no_overflowjj:
addl %edi, %esi
cmpl %edi, %esi
setae %al
movzbl %al, %eax
ret
//===---------------------------------------------------------------------===//