[PATCH] D46750: [SROA] pr37267: fix assertion failure while integer widening

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 11 05:36:11 PDT 2018


inouehrs created this revision.
inouehrs added reviewers: chandlerc, rnk, efriedma.
Herald added a subscriber: fedor.sergeev.

The current integer widening does not support rewriting partial split spice in `rewriteIntegerStore` (and `rewriteIntegerLoad`). 
This patch adds explicit check for this in `isIntegerWideningViableForSlice`.
Before r322533, splitting is allowed only for the whole-alloca slice and hence the above case is implicitly rejected by another check `if (DL.getTypeStoreSize(ValueTy) > Size)` because whole-alloca slice is larger than the partition.

By adding this case, there was no visible difference in the number of widening happened during the bootstrap test.


https://reviews.llvm.org/D46750

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/pr37267.ll


Index: test/Transforms/SROA/pr37267.ll
===================================================================
--- /dev/null
+++ test/Transforms/SROA/pr37267.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -sroa -disable-output
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32:64-S128"
+target triple = "sparcv9-sun-solaris"
+
+; PR37267
+; Check that we don't crash on this test.
+
+define void @f2() {
+bb1:
+  %a.3 = alloca [6 x i16], align 1
+  %_tmp3 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
+  %_tmp5 = bitcast i16* %_tmp3 to i32*
+  store i32 131074, i32* %_tmp5, align 1
+  %_tmp8 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
+  %_tmp10 = bitcast i16* %_tmp8 to i32*
+  store i32 131074, i32* %_tmp10, align 1
+  %_tmp12 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
+  %_tmp13 = load i16, i16* %_tmp12, align 1
+  %_tmp15 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
+  %_tmp16 = load i16, i16* %_tmp15, align 1
+  ret void
+}
+
Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -1950,7 +1950,7 @@
                                             bool &WholeAllocaOp) {
   uint64_t Size = DL.getTypeStoreSize(AllocaTy);
 
-  uint64_t RelBegin = S.beginOffset() - AllocBeginOffset;
+  int64_t RelBegin = S.beginOffset() - AllocBeginOffset;
   uint64_t RelEnd = S.endOffset() - AllocBeginOffset;
 
   // We can't reasonably handle cases where the load or store extends past
@@ -1966,6 +1966,9 @@
     // We can't handle loads that extend past the allocated memory.
     if (DL.getTypeStoreSize(LI->getType()) > Size)
       return false;
+    // We can't handle split slice tails.
+    if (RelBegin < 0)
+      return false;
     // Note that we don't count vector loads or stores as whole-alloca
     // operations which enable integer widening because we would prefer to use
     // vector widening instead.
@@ -1987,6 +1990,9 @@
     // We can't handle stores that extend past the allocated memory.
     if (DL.getTypeStoreSize(ValueTy) > Size)
       return false;
+    // We can't handle split slice tails.
+    if (RelBegin < 0)
+      return false;
     // Note that we don't count vector loads or stores as whole-alloca
     // operations which enable integer widening because we would prefer to use
     // vector widening instead.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46750.146306.patch
Type: text/x-patch
Size: 2509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180511/f30ecc52/attachment.bin>


More information about the llvm-commits mailing list