[PATCH] D20638: [LIR] Fix mis-compilation with unwinding

Haicheng Wu via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 08:34:17 PDT 2016


haicheng updated this revision to Diff 62879.
haicheng marked 5 inline comments as done.
haicheng added a comment.

Sorry for the long delay.

Just use computeLoopSafetyInfo (which calls isGuaranteedToTransferExecutionToSuccessor) to decide whether the loop may throw or not.

Please take a look.


Repository:
  rL LLVM

http://reviews.llvm.org/D20638

Files:
  lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  test/Transforms/LoopIdiom/unwind.ll

Index: test/Transforms/LoopIdiom/unwind.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopIdiom/unwind.ll
@@ -0,0 +1,33 @@
+; RUN: opt -loop-idiom < %s -S | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @ff()
+
+define void @test(i8* noalias nocapture %base, i64 %size) #1 {
+entry:
+  %cmp3 = icmp eq i64 %size, 0
+  br i1 %cmp3, label %for.end, label %for.body.preheader
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+; CHECK-LABEL: @test(
+; CHECK-NOT: llvm.memset
+  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
+  tail call void @ff()
+  %arrayidx = getelementptr inbounds i8, i8* %base, i64 %indvars.iv
+  store i8 0, i8* %arrayidx, align 1
+  %indvars.iv.next = add i64 %indvars.iv, 1
+  %exitcond = icmp ne i64 %indvars.iv.next, %size
+  br i1 %exitcond, label %for.body, label %for.end.loopexit
+
+for.end.loopexit:                                 ; preds = %for.body
+  br label %for.end
+
+for.end:                                          ; preds = %for.end.loopexit, %entry
+  ret void
+}
+
+attributes #1 = { uwtable }
Index: lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -216,6 +216,14 @@
                << CurLoop->getHeader()->getName() << "\n");
 
   bool MadeChange = false;
+
+  // Compute loop safety information.
+  LoopSafetyInfo SafetyInfo;
+  computeLoopSafetyInfo(&SafetyInfo, CurLoop);
+  // Give up if the loop may throw.
+  if (SafetyInfo.MayThrow)
+    return MadeChange;
+
   // Scan all the blocks in the loop that are not in subloops.
   for (auto *BB : CurLoop->getBlocks()) {
     // Ignore blocks in subloops.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20638.62879.patch
Type: text/x-patch
Size: 2039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160706/3c257fc9/attachment.bin>


More information about the llvm-commits mailing list