[llvm] r292197 - [InstCombine] Don't DSE across readnone functions that may throw
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 16 21:45:10 PST 2017
Author: sanjoy
Date: Mon Jan 16 23:45:09 2017
New Revision: 292197
URL: http://llvm.org/viewvc/llvm-project?rev=292197&view=rev
Log:
[InstCombine] Don't DSE across readnone functions that may throw
Summary: Depends on D28740
Reviewers: dberlin, chandlerc, hfinkel, majnemer
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D28742
Added:
llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=292197&r1=292196&r2=292197&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Mon Jan 16 23:45:09 2017
@@ -1267,8 +1267,8 @@ Instruction *InstCombiner::visitStoreIns
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,8 +1391,8 @@ bool InstCombiner::SimplifyStoreAtEndOfB
}
// 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() ||
- BBI == OtherBB->begin())
+ if (BBI->mayReadFromMemory() || BBI->mayThrow() ||
+ BBI->mayWriteToMemory() || BBI == OtherBB->begin())
return false;
}
@@ -1401,7 +1401,7 @@ bool InstCombiner::SimplifyStoreAtEndOfB
// 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;
}
}
Added: llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll?rev=292197&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll Mon Jan 16 23:45:09 2017
@@ -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
+}
More information about the llvm-commits
mailing list