[PATCH] D28742: [InstCombine] Don't DSE across readnone functions that may throw
Sanjoy Das via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 16 21:07:38 PST 2017
sanjoy updated this revision to Diff 84628.
sanjoy added a comment.
- Address review: remove usage of mayReadMemoryOrThrow()
https://reviews.llvm.org/D28742
Files:
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/readnone-maythrow.ll
Index: test/Transforms/InstCombine/readnone-maythrow.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/readnone-maythrow.ll
@@ -0,0 +1,34 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+declare void @readnone_but_may_throw() readnone
+
+define void @f_0(i32* %ptr) {
+; CHECK-LABEL: @f_0(
+entry:
+; CHECK: store i32 10, i32* %ptr
+; CHECK-NEXT: call void @readnone_but_may_throw()
+; CHECK-NEXT: store i32 20, i32* %ptr, align 4
+; CHECK: ret void
+
+ store i32 10, i32* %ptr
+ call void @readnone_but_may_throw()
+ store i32 20, i32* %ptr
+ ret void
+}
+
+define void @f_1(i1 %cond, i32* %ptr) {
+; CHECK-LABEL: @f_1(
+; CHECK: store i32 10, i32* %ptr
+; CHECK-NEXT: call void @readnone_but_may_throw()
+
+ store i32 10, i32* %ptr
+ call void @readnone_but_may_throw()
+ br i1 %cond, label %left, label %merge
+
+left:
+ store i32 20, i32* %ptr
+ br label %merge
+
+merge:
+ ret void
+}
Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1267,8 +1267,8 @@
break;
}
- // Don't skip over loads or things that can modify memory.
- if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory())
+ // Don't skip over loads, throws or things that can modify memory.
+ if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory() || BBI->mayThrow())
break;
}
@@ -1391,7 +1391,7 @@
}
// If we find something that may be using or overwriting the stored
// value, or if we run out of instructions, we can't do the xform.
- if (BBI->mayReadFromMemory() || BBI->mayWriteToMemory() ||
+ if (BBI->mayReadFromMemory() || BBI->mayThrow() || BBI->mayWriteToMemory() ||
BBI == OtherBB->begin())
return false;
}
@@ -1401,7 +1401,7 @@
// StoreBB.
for (BasicBlock::iterator I = StoreBB->begin(); &*I != &SI; ++I) {
// FIXME: This should really be AA driven.
- if (I->mayReadFromMemory() || I->mayWriteToMemory())
+ if (I->mayReadFromMemory() || I->mayThrow() || I->mayWriteToMemory())
return false;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28742.84628.patch
Type: text/x-patch
Size: 2310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170117/cb270485/attachment-0001.bin>
More information about the llvm-commits
mailing list