<div dir="ltr">Sorry, I forgot to mention in the commit log -- there's no test case as triggering this requires very fragile ordering of operations and so wasn't stable. (This is from James's original patch.)</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 21, 2014 at 3:16 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chandlerc<br>
Date: Tue Jan 21 17:16:05 2014<br>
New Revision: 199771<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=199771&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=199771&view=rev</a><br>
Log:<br>
[SROA] Fix a bug which could cause the common type finding to return<br>
inconsistent results for different orderings of alloca slices. The<br>
fundamental issue is that it is just always a mistake to return early<br>
from this function. There is no effective early exit to leverage. This<br>
patch stops trynig to do so and simplifies the code a bit as<br>
a consequence.<br>
<br>
Original diagnosis and patch by James Molloy with some name tweaks by me<br>
in part reflecting feedback from Duncan Smith on the mailing list.<br>
<br>
Modified:<br>
llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=199771&r1=199770&r2=199771&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=199771&r1=199770&r2=199771&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Tue Jan 21 17:16:05 2014<br>
@@ -957,7 +957,11 @@ static Type *findCommonType(AllocaSlices<br>
AllocaSlices::const_iterator E,<br>
uint64_t EndOffset) {<br>
Type *Ty = 0;<br>
- bool IgnoreNonIntegralTypes = false;<br>
+ bool TyIsCommon = true;<br>
+ IntegerType *ITy = 0;<br>
+<br>
+ // Note that we need to look at *every* alloca slice's Use to ensure we<br>
+ // always get consistent results regardless of the order of slices.<br>
for (AllocaSlices::const_iterator I = B; I != E; ++I) {<br>
Use *U = I->getUse();<br>
if (isa<IntrinsicInst>(*U->getUser()))<br>
@@ -970,37 +974,30 @@ static Type *findCommonType(AllocaSlices<br>
UserTy = LI->getType();<br>
} else if (StoreInst *SI = dyn_cast<StoreInst>(U->getUser())) {<br>
UserTy = SI->getValueOperand()->getType();<br>
- } else {<br>
- IgnoreNonIntegralTypes = true; // Give up on anything but an iN type.<br>
- continue;<br>
}<br>
<br>
- if (IntegerType *ITy = dyn_cast<IntegerType>(UserTy)) {<br>
+ if (!UserTy || (Ty && Ty != UserTy))<br>
+ TyIsCommon = false; // Give up on anything but an iN type.<br>
+ else<br>
+ Ty = UserTy;<br>
+<br>
+ if (IntegerType *UserITy = dyn_cast_or_null<IntegerType>(UserTy)) {<br>
// If the type is larger than the partition, skip it. We only encounter<br>
// this for split integer operations where we want to use the type of the<br>
// entity causing the split. Also skip if the type is not a byte width<br>
// multiple.<br>
- if (ITy->getBitWidth() % 8 != 0 ||<br>
- ITy->getBitWidth() / 8 > (EndOffset - B->beginOffset()))<br>
+ if (UserITy->getBitWidth() % 8 != 0 ||<br>
+ UserITy->getBitWidth() / 8 > (EndOffset - B->beginOffset()))<br>
continue;<br>
<br>
- // If we have found an integer type use covering the alloca, use that<br>
- // regardless of the other types, as integers are often used for<br>
- // a "bucket of bits" type.<br>
- //<br>
- // NB: This *must* be the only return from inside the loop so that the<br>
- // order of slices doesn't impact the computed type.<br>
- return ITy;<br>
- } else if (IgnoreNonIntegralTypes) {<br>
- continue;<br>
+ // Track the largest bitwidth integer type used in this way in case there<br>
+ // is no common type.<br>
+ if (!ITy || ITy->getBitWidth() < UserITy->getBitWidth())<br>
+ ITy = UserITy;<br>
}<br>
-<br>
- if (Ty && Ty != UserTy)<br>
- IgnoreNonIntegralTypes = true; // Give up on anything but an iN type.<br>
-<br>
- Ty = UserTy;<br>
}<br>
- return Ty;<br>
+<br>
+ return TyIsCommon ? Ty : ITy;<br>
}<br>
<br>
/// PHI instructions that use an alloca and are subsequently loaded can be<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>