<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 8:15 PM, Matthias Braun via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">MatzeB created this revision.<br>
MatzeB added reviewers: chandlerc, sunfish, baldrick.<br>
MatzeB added a subscriber: llvm-commits.<br>
MatzeB set the repository for this revision to rL LLVM.<br>
Herald added a subscriber: mcrosier.<br>
<br>
The majority of stripPointerCastsAndOffsets() queries can be resolved<br>
after checking 1 or 2 values. This patch delays the creation and<br>
insertion into a SmallPtrSet until we have to check more than that. This<br>
slightly improves compile time in my benchmarks.<br>
<br>
Repository:<br>
rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D16622" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16622</a><br>
<br>
Files:<br>
lib/IR/Value.cpp<br>
<br>
Index: lib/IR/Value.cpp<br>
===================================================================<br>
--- lib/IR/Value.cpp<br>
+++ lib/IR/Value.cpp<br>
@@ -421,43 +421,59 @@<br>
};<br>
<br>
template <PointerStripKind StripKind><br>
+static Value *stripOne(Value *V) {<br>
+ if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {<br>
+ switch (StripKind) {<br>
+ case PSK_ZeroIndicesAndAliases:<br>
+ case PSK_ZeroIndices:<br>
+ if (!GEP->hasAllZeroIndices())<br>
+ return nullptr;<br>
+ break;<br>
+ case PSK_InBoundsConstantIndices:<br>
+ if (!GEP->hasAllConstantIndices())<br>
+ return nullptr;<br>
+ // fallthrough<br>
+ case PSK_InBounds:<br>
+ if (!GEP->isInBounds())<br>
+ return nullptr;<br>
+ break;<br>
+ }<br>
+ return GEP->getPointerOperand();<br>
+ } else if (Operator::getOpcode(V) == Instruction::BitCast ||<br></blockquote><div><br></div><div>Drop the "else after return"s here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ Operator::getOpcode(V) == Instruction::AddrSpaceCast) {<br>
+ return cast<Operator>(V)->getOperand(0);<br>
+ } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {<br>
+ if (StripKind == PSK_ZeroIndices || GA->mayBeOverridden())<br>
+ return nullptr;<br>
+ return GA->getAliasee();<br>
+ } else {<br>
+ return nullptr;<br>
+ }<br>
+}<br>
+<br>
+template <PointerStripKind StripKind><br>
static Value *stripPointerCastsAndOffsets(Value *V) {<br>
if (!V->getType()->isPointerTy())<br>
return V;<br>
<br>
+ // This function is performance sensitive so try the common case first<br>
+ // before constructing the SmallPtrSet.<br>
+ Value *Next = stripOne<StripKind>(V);<br>
+ if (Next == nullptr)<br>
+ return V;<br>
+<br>
// Even though we don't look through PHI nodes, we could be called on an<br>
// instruction in an unreachable block, which may be on a cycle.<br>
SmallPtrSet<Value *, 4> Visited;<br>
-<br>
Visited.insert(V);<br>
+ if (!Visited.insert(Next).second)<br>
+ return Next;<br>
+ V = Next;<br>
do {<br>
- if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {<br>
- switch (StripKind) {<br>
- case PSK_ZeroIndicesAndAliases:<br>
- case PSK_ZeroIndices:<br>
- if (!GEP->hasAllZeroIndices())<br>
- return V;<br>
- break;<br>
- case PSK_InBoundsConstantIndices:<br>
- if (!GEP->hasAllConstantIndices())<br>
- return V;<br>
- // fallthrough<br>
- case PSK_InBounds:<br>
- if (!GEP->isInBounds())<br>
- return V;<br>
- break;<br>
- }<br>
- V = GEP->getPointerOperand();<br>
- } else if (Operator::getOpcode(V) == Instruction::BitCast ||<br>
- Operator::getOpcode(V) == Instruction::AddrSpaceCast) {<br>
- V = cast<Operator>(V)->getOperand(0);<br>
- } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {<br>
- if (StripKind == PSK_ZeroIndices || GA->mayBeOverridden())<br>
- return V;<br>
- V = GA->getAliasee();<br>
- } else {<br>
+ Next = stripOne<StripKind>(V);<br>
+ if (Next == nullptr)<br>
return V;<br>
- }<br>
+ V = Next;<br>
assert(V->getType()->isPointerTy() && "Unexpected operand type!");<br>
} while (Visited.insert(V).second);<br>
<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div></div>