[PATCH] Fix Bug in SROA transformation [PR18615]

Karthik Bhat kv.bhat at samsung.com
Wed Feb 19 03:56:54 PST 2014


  Hi Rafael,
  Thanks for the inputs. I have modified the test case but unfortunetly i'm not able to reproduce the issue with just opt -sroa 18615.ll. A combination of passes which are run in O1 and onwards seems to be resulting in the problem. The issue is reproduced if i run opt -O1 18615.ll .

  I tried out few combination of passes that run on O1 and above along with sroa but the exact combination of passes which is resulting in the issue could not be found.
  Do you think a test case which runs "opt -O1 18615.ll" will be sufficient as we are able to reproduce the issue here?

  In the patch we are just checking if insertUse resulted in marking the instruction as dead in which case we return instead of checking if we ended up inserting at a valid index in the map. Does this patch look good?

  Thanks for spending your time on this. Your inputs will be valuable.
  Thanks
  Karthik Bhat

Hi chandlerc, rafael,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2759?vs=7154&id=7201#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 -O1 -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.3.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140219/500daf34/attachment.bin>


More information about the llvm-commits mailing list