[PATCH] D20638: [LIR] Fix mis-compilation with unwinding
Haicheng Wu via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 12:58:45 PDT 2016
haicheng created this revision.
haicheng added reviewers: mcrosier, mssimpso.
haicheng added subscribers: majnemer, eli.friedman, sanjoy, llvm-commits.
haicheng set the repository for this revision to rL LLVM.
Herald added subscribers: mzolotukhin, mcrosier.
To fix [[ https://llvm.org/bugs/show_bug.cgi?id=27859 | PR27859 ]], bail out if there is an instruction may throw.
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,51 @@
+; ModuleID = 'tmp.cpp'
+; 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"
+
+ at _ZTIi = external constant i8*
+ at ff = global void ()* @f, align 8
+ at gg = global void (i8*, i32)* @g, align 8
+
+define void @f() {
+entry:
+ %exception = tail call i8* @__cxa_allocate_exception(i64 4) #5
+ %0 = bitcast i8* %exception to i32*
+ store i32 1, i32* %0, align 16
+ tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
+ unreachable
+}
+
+declare i8* @__cxa_allocate_exception(i64)
+
+declare void @__cxa_throw(i8*, i8*, i8*)
+
+define void @g(i8* noalias nocapture %base, i32 %size) {
+entry:
+ %cmp4 = icmp eq i32 %size, 0
+ br i1 %cmp4, label %for.cond.cleanup, label %for.body.preheader
+
+for.body.preheader: ; preds = %entry
+ br label %for.body
+
+for.cond.cleanup.loopexit: ; preds = %for.body
+ br label %for.cond.cleanup
+
+for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
+ ret void
+
+for.body: ; preds = %for.body.preheader, %for.body
+ %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
+ %0 = load void ()*, void ()** @ff, align 8
+ tail call void %0()
+ %arrayidx = getelementptr inbounds i8, i8* %base, i64 %indvars.iv
+ store i8 0, i8* %arrayidx, align 1
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %lftr.wideiv = trunc i64 %indvars.iv.next to i32
+ %exitcond = icmp eq i32 %lftr.wideiv, %size
+ br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
+; CHECK-LABEL: @g(
+; CHECK-NOT: llvm.memset
+}
+
Index: lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -384,6 +384,13 @@
StoreRefsForMemsetPattern.clear();
StoreRefsForMemcpy.clear();
for (Instruction &I : *BB) {
+ if (I.mayThrow()) {
+ StoreRefsForMemset.clear();
+ StoreRefsForMemsetPattern.clear();
+ StoreRefsForMemcpy.clear();
+ return;
+ }
+
StoreInst *SI = dyn_cast<StoreInst>(&I);
if (!SI)
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20638.58478.patch
Type: text/x-patch
Size: 2518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160525/a2834091/attachment.bin>
More information about the llvm-commits
mailing list