[llvm] e22af03 - [Sink] Don't sink non-willreturn calls (PR51188)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 07:35:27 PDT 2022
Author: Nikita Popov
Date: 2022-04-07T16:35:05+02:00
New Revision: e22af03a794d633915d0b51c15e05bb9cb9b4ec9
URL: https://github.com/llvm/llvm-project/commit/e22af03a794d633915d0b51c15e05bb9cb9b4ec9
DIFF: https://github.com/llvm/llvm-project/commit/e22af03a794d633915d0b51c15e05bb9cb9b4ec9.diff
LOG: [Sink] Don't sink non-willreturn calls (PR51188)
Fixes https://github.com/llvm/llvm-project/issues/51188.
Added:
Modified:
llvm/lib/Transforms/Scalar/Sink.cpp
llvm/test/Transforms/Sink/call.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp
index ac6f34aab4150..e8fde53005f0b 100644
--- a/llvm/lib/Transforms/Scalar/Sink.cpp
+++ b/llvm/lib/Transforms/Scalar/Sink.cpp
@@ -43,7 +43,7 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA,
}
if (Inst->isTerminator() || isa<PHINode>(Inst) || Inst->isEHPad() ||
- Inst->mayThrow())
+ Inst->mayThrow() || !Inst->willReturn())
return false;
if (auto *Call = dyn_cast<CallBase>(Inst)) {
diff --git a/llvm/test/Transforms/Sink/call.ll b/llvm/test/Transforms/Sink/call.ll
index 2da58ebb26838..2fb339a69ac8c 100644
--- a/llvm/test/Transforms/Sink/call.ll
+++ b/llvm/test/Transforms/Sink/call.ll
@@ -4,11 +4,11 @@
declare i32 @f_load_global() nounwind willreturn readonly
declare i32 @f_load_global_throwable() willreturn readonly
declare i32 @f_load_global_may_not_return() nounwind readonly
-declare i32 @f_load_arg(i32*) nounwind readonly argmemonly
-declare void @f_store_global(i32) nounwind
-declare void @f_store_arg(i32*) nounwind argmemonly
-declare void @f_readonly_arg(i32* readonly, i32*) nounwind argmemonly
-declare i32 @f_readnone(i32) nounwind readnone
+declare i32 @f_load_arg(i32*) nounwind willreturn readonly argmemonly
+declare void @f_store_global(i32) nounwind willreturn
+declare void @f_store_arg(i32*) nounwind willreturn argmemonly
+declare void @f_readonly_arg(i32* readonly, i32*) nounwind willreturn argmemonly
+declare i32 @f_readnone(i32) nounwind willreturn readnone
@A = external global i32
@B = external global i32
@@ -51,9 +51,9 @@ false:
define i32 @test_may_not_return_no_stores(i1 %z) {
; CHECK-LABEL: @test_may_not_return_no_stores(
+; CHECK-NEXT: [[L:%.*]] = call i32 @f_load_global_may_not_return()
; CHECK-NEXT: br i1 [[Z:%.*]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
-; CHECK-NEXT: [[L:%.*]] = call i32 @f_load_global_may_not_return()
; CHECK-NEXT: ret i32 [[L]]
; CHECK: false:
; CHECK-NEXT: ret i32 0
More information about the llvm-commits
mailing list