aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorDianQK <dianqk@dianqk.net>2024-07-16 19:06:32 +0800
committerGitHub <noreply@github.com>2024-07-16 19:06:32 +0800
commit8afb6432c239a3f5502c5014ebab6b372d7b3d50 (patch)
tree1b82cee8360baf736a39b0b21070ba5bfd6ba16d /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parentcc97a0d34787e4c9151fa894531ad9d07486a6ae (diff)
downloadllvm-8afb6432c239a3f5502c5014ebab6b372d7b3d50.zip
llvm-8afb6432c239a3f5502c5014ebab6b372d7b3d50.tar.gz
llvm-8afb6432c239a3f5502c5014ebab6b372d7b3d50.tar.bz2
[SimplifyCFG] Select the first instruction that we can handle in `passingValueIsAlwaysUndefined` (#98802)
Fixes #98799.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 3fa3c0f..8f717cb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7573,11 +7573,31 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
return false;
if (C->isNullValue() || isa<UndefValue>(C)) {
- // Only look at the first use, avoid hurting compile time with long uselists
- auto *Use = cast<Instruction>(*I->user_begin());
+ // Only look at the first use we can handle, avoid hurting compile time with
+ // long uselists
+ auto FindUse = llvm::find_if(I->users(), [](auto *U) {
+ auto *Use = cast<Instruction>(U);
+ // Change this list when we want to add new instructions.
+ switch (Use->getOpcode()) {
+ default:
+ return false;
+ case Instruction::GetElementPtr:
+ case Instruction::Ret:
+ case Instruction::BitCast:
+ case Instruction::Load:
+ case Instruction::Store:
+ case Instruction::Call:
+ case Instruction::CallBr:
+ case Instruction::Invoke:
+ return true;
+ }
+ });
+ if (FindUse == I->user_end())
+ return false;
+ auto *Use = cast<Instruction>(*FindUse);
// Bail out if Use is not in the same BB as I or Use == I or Use comes
- // before I in the block. The latter two can be the case if Use is a PHI
- // node.
+ // before I in the block. The latter two can be the case if Use is a
+ // PHI node.
if (Use->getParent() != I->getParent() || Use == I || Use->comesBefore(I))
return false;