llvm.org GIT mirror llvm / d138a7b
[PowerPC] Materialize i64 constants using bit inversion Materializing full 64-bit constants on PPC64 can be expensive, requiring up to 5 instructions depending on the locations of the non-zero bits. Sometimes materializing the bit-reversed constant, and then flipping the bits, requires fewer instructions than the direct method. If so, do that instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225132 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 5 years ago
2 changed file(s) with 50 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
543543
544544 // Predict the number of instructions that would be generated by calling
545545 // SelectInt64(N).
546 static unsigned SelectInt64Count(int64_t Imm) {
546 static unsigned SelectInt64CountDirect(int64_t Imm) {
547547 // Assume no remaining bits.
548548 unsigned Remainder = 0;
549549 // Assume no shift required.
601601 return Result;
602602 }
603603
604 static unsigned SelectInt64Count(int64_t Imm) {
605 unsigned DirectCount = SelectInt64CountDirect(Imm);
606
607 // If might be cheaper to materialize the bit-inverted constant, and then
608 // flip the bits (which takes one nor instruction).
609 unsigned NotDirectCount = SelectInt64CountDirect(~(uint64_t) Imm) + 1;
610 if (NotDirectCount < DirectCount)
611 return NotDirectCount;
612
613 return DirectCount;
614 }
615
604616 // Select a 64-bit constant. For cost-modeling purposes, SelectInt64Count
605617 // (above) needs to be kept in sync with this function.
606 static SDNode *SelectInt64(SelectionDAG *CurDAG, SDLoc dl, int64_t Imm) {
618 static SDNode *SelectInt64Direct(SelectionDAG *CurDAG, SDLoc dl, int64_t Imm) {
607619 // Assume no remaining bits.
608620 unsigned Remainder = 0;
609621 // Assume no shift required.
675687 }
676688
677689 return Result;
690 }
691
692 static SDNode *SelectInt64(SelectionDAG *CurDAG, SDLoc dl, int64_t Imm) {
693 unsigned DirectCount = SelectInt64CountDirect(Imm);
694
695 // If might be cheaper to materialize the bit-inverted constant, and then
696 // flip the bits (which takes one nor instruction).
697 unsigned NotDirectCount = SelectInt64CountDirect(~(uint64_t) Imm) + 1;
698 if (NotDirectCount < DirectCount) {
699 SDValue NotDirectVal =
700 SDValue(SelectInt64Direct(CurDAG, dl, ~(uint64_t) Imm), 0);
701 return CurDAG->getMachineNode(PPC::NOR8, dl, MVT::i64, NotDirectVal,
702 NotDirectVal);
703 }
704
705 return SelectInt64Direct(CurDAG, dl, Imm);
678706 }
679707
680708 // Select a 64-bit constant.
0 ; RUN: llc -mcpu=ppc64 < %s | FileCheck %s
1 target datalayout = "E-m:e-i64:64-n32:64"
2 target triple = "powerpc64-unknown-linux-gnu"
3
4 ; Function Attrs: nounwind readnone
5 define i64 @cn1() #0 {
6 entry:
7 ret i64 281474976710655
8
9 ; CHECK-LABEL: @cn1
10 ; CHECK: li [[REG1:[0-9]+]], 0
11 ; CHECK: ori [[REG2:[0-9]+]], [[REG1]], 65535
12 ; CHECK: sldi [[REG3:[0-9]+]], [[REG2]], 48
13 ; CHECK: nor 3, [[REG3]], [[REG3]]
14 ; CHECK: blr
15 }
16
17 attributes #0 = { nounwind readnone }
18
19