Skip to content

Commit dec5170

Browse files
author
Dale Johannesen
committed
Rewrite ppc code generated for __sync_{bool|val}_compare_and_swap
so that lwarx and stwcx are always executed the same number of times. This is important for performance, I'm told. llvm-svn: 55163
1 parent 8af2d65 commit dec5170

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,20 +4056,20 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
40564056

40574057
// loopMBB:
40584058
// l[wd]arx dest, ptr
4059-
// cmp[wd] dest, oldval
4060-
// bne- exitMBB
4059+
// cmp[wd] CR1, dest, oldval
40614060
// st[wd]cx. newval, ptr
4061+
// bne- CR1, exitMBB
40624062
// bne- loopMBB
40634063
// fallthrough --> exitMBB
40644064
BB = loopMBB;
40654065
BuildMI(BB, TII->get(is64bit ? PPC::LDARX : PPC::LWARX), dest)
40664066
.addReg(ptrA).addReg(ptrB);
4067-
BuildMI(BB, TII->get(is64bit ? PPC::CMPD : PPC::CMPW), PPC::CR0)
4067+
BuildMI(BB, TII->get(is64bit ? PPC::CMPD : PPC::CMPW), PPC::CR1)
40684068
.addReg(oldval).addReg(dest);
4069-
BuildMI(BB, TII->get(PPC::BCC))
4070-
.addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(exitMBB);
40714069
BuildMI(BB, TII->get(is64bit ? PPC::STDCX : PPC::STWCX))
40724070
.addReg(newval).addReg(ptrA).addReg(ptrB);
4071+
BuildMI(BB, TII->get(PPC::BCC))
4072+
.addImm(PPC::PRED_NE).addReg(PPC::CR1).addMBB(exitMBB);
40734073
BuildMI(BB, TII->get(PPC::BCC))
40744074
.addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB);
40754075
BB->addSuccessor(loopMBB);

llvm/lib/Target/PowerPC/PPCInstr64Bit.td

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@ let usesCustomDAGSchedInserter = 1 in {
123123
(outs G8RC:$dst), (ins memrr:$ptr, G8RC:$incr),
124124
"${:comment} ATOMIC_LOAD_ADD_I64 PSEUDO!",
125125
[(set G8RC:$dst, (PPCatomic_load_add xoaddr:$ptr, G8RC:$incr))]>;
126-
def ATOMIC_CMP_SWAP_I64 : Pseudo<
127-
(outs G8RC:$dst), (ins memrr:$ptr, G8RC:$old, G8RC:$new),
128-
"${:comment} ATOMIC_CMP_SWAP_I64 PSEUDO!",
129-
[(set G8RC:$dst, (PPCatomic_cmp_swap xoaddr:$ptr, G8RC:$old, G8RC:$new))]>;
130126
def ATOMIC_SWAP_I64 : Pseudo<
131127
(outs G8RC:$dst), (ins memrr:$ptr, G8RC:$new),
132128
"${:comment} ATOMIC_SWAP_I64 PSEUDO!",
133129
[(set G8RC:$dst, (PPCatomic_swap xoaddr:$ptr, G8RC:$new))]>;
134130
}
131+
let Uses = [CR0, CR1] in {
132+
def ATOMIC_CMP_SWAP_I64 : Pseudo<
133+
(outs G8RC:$dst), (ins memrr:$ptr, G8RC:$old, G8RC:$new),
134+
"${:comment} ATOMIC_CMP_SWAP_I64 PSEUDO!",
135+
[(set G8RC:$dst,
136+
(PPCatomic_cmp_swap xoaddr:$ptr, G8RC:$old, G8RC:$new))]>;
137+
}
135138
}
136139

137140
// Instructions to support atomic operations

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,18 @@ let usesCustomDAGSchedInserter = 1 in {
553553
(outs GPRC:$dst), (ins memrr:$ptr, GPRC:$incr),
554554
"${:comment} ATOMIC_LOAD_ADD_I32 PSEUDO!",
555555
[(set GPRC:$dst, (PPCatomic_load_add xoaddr:$ptr, GPRC:$incr))]>;
556-
def ATOMIC_CMP_SWAP_I32 : Pseudo<
557-
(outs GPRC:$dst), (ins memrr:$ptr, GPRC:$old, GPRC:$new),
558-
"${:comment} ATOMIC_CMP_SWAP_I32 PSEUDO!",
559-
[(set GPRC:$dst, (PPCatomic_cmp_swap xoaddr:$ptr, GPRC:$old, GPRC:$new))]>;
560556
def ATOMIC_SWAP_I32 : Pseudo<
561557
(outs GPRC:$dst), (ins memrr:$ptr, GPRC:$new),
562558
"${:comment} ATOMIC_SWAP_I32 PSEUDO!",
563559
[(set GPRC:$dst, (PPCatomic_swap xoaddr:$ptr, GPRC:$new))]>;
564560
}
561+
let Uses = [CR0, CR1] in {
562+
def ATOMIC_CMP_SWAP_I32 : Pseudo<
563+
(outs GPRC:$dst), (ins memrr:$ptr, GPRC:$old, GPRC:$new),
564+
"${:comment} ATOMIC_CMP_SWAP_I32 PSEUDO!",
565+
[(set GPRC:$dst,
566+
(PPCatomic_cmp_swap xoaddr:$ptr, GPRC:$old, GPRC:$new))]>;
567+
}
565568
}
566569

567570
// Instructions to support atomic operations

0 commit comments

Comments
 (0)