llvm.org GIT mirror llvm / bf8ae84
Add some notes about better flag handling. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41808 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
3 changed file(s) with 102 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
527527 This apparently occurs in real code.
528528
529529 //===---------------------------------------------------------------------===//
530
531 This:
532 #include
533 std::pair full_add(unsigned a, unsigned b)
534 { return std::make_pair(a + b, a + b < a); }
535 bool no_overflow(unsigned a, unsigned b)
536 { return !full_add(a, b).second; }
537
538 Should compile to:
539
540 _Z8full_addjj:
541 adds r2, r1, r2
542 movcc r1, #0
543 movcs r1, #1
544 str r2, [r0, #0]
545 strb r1, [r0, #4]
546 mov pc, lr
547
548 _Z11no_overflowjj:
549 cmn r0, r1
550 movcs r0, #0
551 movcc r0, #1
552 mov pc, lr
553
554 not:
555
556 __Z8full_addjj:
557 add r3, r2, r1
558 str r3, [r0]
559 mov r2, #1
560 mov r12, #0
561 cmp r3, r1
562 movlo r12, r2
563 str r12, [r0, #+4]
564 bx lr
565 __Z11no_overflowjj:
566 add r3, r1, r0
567 mov r2, #1
568 mov r1, #0
569 cmp r3, r0
570 movhs r1, r2
571 mov r0, r1
572 bx lr
573
574 //===---------------------------------------------------------------------===//
676676 cmplwi cr0, r6, 33920
677677 bne cr0, LBB1_1
678678
679 ===-------------------------------------------------------------------------===
680
679 //===---------------------------------------------------------------------===//
680
681 This:
682 #include
683 inline std::pair full_add(unsigned a, unsigned b)
684 { return std::make_pair(a + b, a + b < a); }
685 bool no_overflow(unsigned a, unsigned b)
686 { return !full_add(a, b).second; }
687
688 Should compile to:
689
690 __Z11no_overflowjj:
691 add r4,r3,r4
692 subfc r3,r3,r4
693 li r3,0
694 adde r3,r3,r3
695 blr
696
697 (or better) not:
698
699 __Z11no_overflowjj:
700 add r2, r4, r3
701 cmplw cr7, r2, r3
702 mfcr r2
703 rlwinm r2, r2, 29, 31, 31
704 xori r3, r2, 1
705 blr
706
707 //===---------------------------------------------------------------------===//
708
11771177 be pretty easy, and will nuke all the copies.
11781178
11791179 //===---------------------------------------------------------------------===//
1180
1181 This:
1182 #include
1183 inline std::pair full_add(unsigned a, unsigned b)
1184 { return std::make_pair(a + b, a + b < a); }
1185 bool no_overflow(unsigned a, unsigned b)
1186 { return !full_add(a, b).second; }
1187
1188 Should compile to:
1189
1190
1191 _Z11no_overflowjj:
1192 addl %edi, %esi
1193 setae %al
1194 ret
1195
1196 on x86-64, not:
1197
1198 __Z11no_overflowjj:
1199 addl %edi, %esi
1200 cmpl %edi, %esi
1201 setae %al
1202 movzbl %al, %eax
1203 ret
1204
1205
1206 //===---------------------------------------------------------------------===//