From 99b5eb2d3a61b55a61849cebabf1d5d66b4a13c4 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 30 May 2022 15:37:46 +0200 Subject: [Local] Don't remove invoke of non-willreturn function The code was only checking for memory side-effects, but not for divergence side-effects. Replace this with a generic check. (cherry picked from commit 2e101cca690645d63ae4de1eb7b0e11d322448fd) --- llvm/lib/Transforms/Utils/Local.cpp | 2 +- llvm/test/Transforms/SimplifyCFG/invoke.ll | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 9a10535c9310..1c350a2585d0 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2350,7 +2350,7 @@ static bool markAliveBlocks(Function &F, changeToUnreachable(II, false, DTU); Changed = true; } else if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) { - if (II->use_empty() && II->onlyReadsMemory()) { + if (II->use_empty() && !II->mayHaveSideEffects()) { // jump to the normal destination branch. BasicBlock *NormalDestBB = II->getNormalDest(); BasicBlock *UnwindDestBB = II->getUnwindDest(); diff --git a/llvm/test/Transforms/SimplifyCFG/invoke.ll b/llvm/test/Transforms/SimplifyCFG/invoke.ll index db10fa390c1d..175a2c6aadc6 100644 --- a/llvm/test/Transforms/SimplifyCFG/invoke.ll +++ b/llvm/test/Transforms/SimplifyCFG/invoke.ll @@ -83,6 +83,7 @@ lpad: define i32 @invoke_readonly_may_not_return() nounwind personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { ; CHECK-LABEL: @invoke_readonly_may_not_return( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[CALL:%.*]] = call i32 @readonly() ; CHECK-NEXT: ret i32 3 ; entry: -- cgit v1.2.1