From bf8ae84a21011a7263c2a4183fdfd8e5755765a1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 10 Sep 2007 21:43:18 +0000 Subject: [PATCH] Add some notes about better flag handling. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41808 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/README.txt | 45 +++++++++++++++++++++++++++++++++++ lib/Target/PowerPC/README.txt | 30 ++++++++++++++++++++++- lib/Target/X86/README.txt | 27 +++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/lib/Target/ARM/README.txt b/lib/Target/ARM/README.txt index 3db8f54f50c..f05ae1c4230 100644 --- a/lib/Target/ARM/README.txt +++ b/lib/Target/ARM/README.txt @@ -528,3 +528,48 @@ _foo: This apparently occurs in real code. //===---------------------------------------------------------------------===// + +This: + #include + std::pair 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 + +//===---------------------------------------------------------------------===// diff --git a/lib/Target/PowerPC/README.txt b/lib/Target/PowerPC/README.txt index 10ee3239546..077bc2555d8 100644 --- a/lib/Target/PowerPC/README.txt +++ b/lib/Target/PowerPC/README.txt @@ -677,5 +677,33 @@ LBB1_1: ;bb cmplwi cr0, r6, 33920 bne cr0, LBB1_1 -===-------------------------------------------------------------------------=== +//===---------------------------------------------------------------------===// + +This: + #include + inline std::pair 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 + +//===---------------------------------------------------------------------===// diff --git a/lib/Target/X86/README.txt b/lib/Target/X86/README.txt index f3b091b6c0f..1f532271362 100644 --- a/lib/Target/X86/README.txt +++ b/lib/Target/X86/README.txt @@ -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 + inline std::pair 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 + + +//===---------------------------------------------------------------------===// -- 2.34.1