[llvm] r186655 - Fix PR16651, an assert introduced in my recent re-work of the innards of

Chandler Carruth chandlerc at gmail.com
Fri Jul 19 00:12:23 PDT 2013


Author: chandlerc
Date: Fri Jul 19 02:12:23 2013
New Revision: 186655

URL: http://llvm.org/viewvc/llvm-project?rev=186655&view=rev
Log:
Fix PR16651, an assert introduced in my recent re-work of the innards of
SROA.

The crux of the issue is that now we track uses of a partition of the
alloca in two places: the iterators over the partitioning uses and the
previously collected split uses vector. We weren't accounting for the
fact that the split uses might invalidate integer widening in ways other
than due to their width (in this case due to being volatile).

Further reduced testcase added to the tests.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp
    llvm/trunk/test/Transforms/SROA/basictest.ll

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=186655&r1=186654&r2=186655&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Fri Jul 19 02:12:23 2013
@@ -1694,20 +1694,14 @@ isIntegerWideningViable(const DataLayout
       !canConvertValue(TD, IntTy, AllocaTy))
     return false;
 
-  // If we have no actual uses of this partition, we're forming a fully
-  // splittable partition. Assume all the operations are easy to widen (they
-  // are if they're splittable), and just check that it's a good idea to form
-  // a single integer.
-  if (I == E)
-    return TD.isLegalInteger(SizeInBits);
-
   uint64_t Size = TD.getTypeStoreSize(AllocaTy);
 
   // While examining uses, we ensure that the alloca has a covering load or
   // store. We don't want to widen the integer operations only to fail to
   // promote due to some other unsplittable entry (which we may make splittable
-  // later).
-  bool WholeAllocaOp = false;
+  // later). However, if there are only splittable uses, go ahead and assume
+  // that we cover the alloca.
+  bool WholeAllocaOp = (I != E) ? false : TD.isLegalInteger(SizeInBits);
 
   for (; I != E; ++I)
     if (!isIntegerWideningViableForPartitioning(TD, AllocaTy, AllocBeginOffset,

Modified: llvm/trunk/test/Transforms/SROA/basictest.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SROA/basictest.ll?rev=186655&r1=186654&r2=186655&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SROA/basictest.ll (original)
+++ llvm/trunk/test/Transforms/SROA/basictest.ll Fri Jul 19 02:12:23 2013
@@ -1317,3 +1317,23 @@ define void @PR15805(i1 %a, i1 %b) {
   %cond = load i64* %cond.in, align 8
   ret void
 }
+
+define void @PR16651(i8* %a) {
+; This test case caused a crash due to the volatile memcpy in combination with
+; lowering to integer loads and stores of a width other than that of the original
+; memcpy.
+;
+; CHECK-LABEL: @PR16651(
+; CHECK: alloca i16
+; CHECK: alloca i8
+; CHECK: alloca i8
+; CHECK: unreachable
+
+entry:
+  %b = alloca i32, align 4
+  %b.cast = bitcast i32* %b to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b.cast, i8* %a, i32 4, i32 4, i1 true)
+  %b.gep = getelementptr inbounds i8* %b.cast, i32 2
+  load i8* %b.gep, align 2
+  unreachable
+}





More information about the llvm-commits mailing list