llvm.org GIT mirror llvm / 434bbb1
Assigning to a local object in a return statement prevents copy elision. NFC. I added a diagnostic along the lines of `-Wpessimizing-move` to detect `return x = y` suppressing copy elision, but I don't know if the diagnostic is really worth it. Anyway, here are the places where my diagnostic reported that copy elision would have been possible if not for the assignment. P1155R1 in the post-San-Diego WG21 (C++ committee) mailing discusses whether WG21 should fix this pitfall by just changing the core language to permit copy elision in cases like these. (Kona update: The bulk of P1155 is proceeding to CWG review, but specifically *not* the parts that explored the notion of permitting copy-elision in these specific cases.) Reviewed By: dblaikie Author: Arthur O'Dwyer Differential Revision: https://reviews.llvm.org/D54885 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359236 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 1 year, 5 months ago
5 changed file(s) with 24 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
6060 MachineBasicBlock::instr_iterator I) {
6161 while (I->isBundledWithSucc())
6262 ++I;
63 return ++I;
63 ++I;
64 return I;
6465 }
6566
6667 /// Returns an iterator pointing beyond the bundle containing \p I.
6869 MachineBasicBlock::const_instr_iterator I) {
6970 while (I->isBundledWithSucc())
7071 ++I;
71 return ++I;
72 ++I;
73 return I;
7274 }
7375
7476 //===----------------------------------------------------------------------===//
127127
128128 BranchProbability operator+(BranchProbability RHS) const {
129129 BranchProbability Prob(*this);
130 return Prob += RHS;
130 Prob += RHS;
131 return Prob;
131132 }
132133
133134 BranchProbability operator-(BranchProbability RHS) const {
134135 BranchProbability Prob(*this);
135 return Prob -= RHS;
136 Prob -= RHS;
137 return Prob;
136138 }
137139
138140 BranchProbability operator*(BranchProbability RHS) const {
139141 BranchProbability Prob(*this);
140 return Prob *= RHS;
142 Prob *= RHS;
143 return Prob;
141144 }
142145
143146 BranchProbability operator*(uint32_t RHS) const {
144147 BranchProbability Prob(*this);
145 return Prob *= RHS;
148 Prob *= RHS;
149 return Prob;
146150 }
147151
148152 BranchProbability operator/(uint32_t RHS) const {
149153 BranchProbability Prob(*this);
150 return Prob /= RHS;
154 Prob /= RHS;
155 return Prob;
151156 }
152157
153158 bool operator==(BranchProbability RHS) const { return N == RHS.N; }
296296 I.Path = Path;
297297 I.Position = Path.size();
298298 I.S = style;
299 return ++I;
299 ++I;
300 return I;
300301 }
301302
302303 reverse_iterator rend(StringRef Path) {
13631363 MBB = MBB->getPrevNode();
13641364 MBBI = MBB->end();
13651365 }
1366 return --MBBI;
1366 --MBBI;
1367 return MBBI;
13671368 }
13681369
13691370 static const Constant *getConstantFromPool(const MachineInstr &MI,
2323 /// Moves I before IP. Returns new insert point.
2424 static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
2525 // If I is IP, move the insert point down.
26 if (I == IP)
27 return ++IP;
28 // Otherwise, move I before IP and return IP.
29 I->moveBefore(&*IP);
26 if (I == IP) {
27 ++IP;
28 } else {
29 // Otherwise, move I before IP and return IP.
30 I->moveBefore(&*IP);
31 }
3032 return IP;
3133 }
3234