[PATCH] Fix Bug in SROA transformation [PR18615]

Karthik Bhat kv.bhat at samsung.com
Wed Feb 19 23:37:19 PST 2014


  Hi Rafael,Chandler,
  I was able to reduce the test case to run the relevent passes which results in the issue.
  Modified test case to run minimal set of passes which results in crash.
  Please let me know your inputs on the patch.
  Thanks
  Karthik

Hi chandlerc, rafael,

http://llvm-reviews.chandlerc.com/D2759

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2759?vs=7201&id=7237#toc

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

Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -524,6 +524,10 @@
     // Insert the use now that we've fixed up the splittable nature.
     insertUse(II, Offset, Size, /*IsSplittable=*/Inserted && Length);
 
+    //If the insert resulted in marking the instruction as dead
+    //i.e. we didn't end up pushing the usage into map then return
+    if (VisitedDeadInsts.count(&II))
+      return;
     // Check that we ended up with a valid index in the map.
     assert(S.Slices[PrevIdx].getUse()->getUser() == &II &&
            "Map index doesn't point back to a slice with this user.");
Index: test/Transforms/SROA/pr18615.ll
===================================================================
--- test/Transforms/SROA/pr18615.ll
+++ test/Transforms/SROA/pr18615.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -early-cse -instcombine -sroa -S
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+
+%struct.S0 = type { i32, i32, i32 }
+
+ at a = common global i32 0, align 4
+
+; Function Attrs: nounwind uwtable
+define void @fn1() #0 {
+entry:
+  %b = alloca i32, align 4
+  %f = alloca [1 x %struct.S0], align 4
+  store i32 -1, i32* %b, align 4
+  %0 = load i32* @a, align 4
+  %tobool = icmp ne i32 %0, 0
+  br i1 %tobool, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  %arrayidx = getelementptr inbounds [1 x %struct.S0]* %f, i32 0, i64 0
+  %1 = load i32* %b, align 4
+  %idxprom = sext i32 %1 to i64
+  %arrayidx1 = getelementptr inbounds [1 x %struct.S0]* %f, i32 0, i64 %idxprom
+  %2 = bitcast %struct.S0* %arrayidx to i8*
+  %3 = bitcast %struct.S0* %arrayidx1 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 12, i32 4, i1 false)
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  ret void
+}
+
+; Function Attrs: nounwind
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #1
+
+attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind }
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2759.4.patch
Type: text/x-patch
Size: 2390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140219/bb263d2f/attachment.bin>


More information about the llvm-commits mailing list