[llvm] [SimplifyCFG] Select the first instruction that we can handle in `passingValueIsAlwaysUndefined` (PR #98802)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 14 07:02:51 PDT 2024


================
@@ -7573,13 +7573,36 @@ 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());
-    // 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.
-    if (Use->getParent() != I->getParent() || Use == I || Use->comesBefore(I))
+    // Only look at the first use we can handle, avoid hurting compile time with
+    // long uselists
+    auto FindUse = llvm::find_if(I->users(), [&I](auto *U) {
+      auto *Use = cast<Instruction>(U);
+      // 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.
+      if (Use->getParent() != I->getParent() || Use == I || Use->comesBefore(I))
+        return false;
+      // Change this list when we want to add new instructions.
+      switch (Use->getOpcode()) {
+      default:
+        return false;
+      case Instruction::GetElementPtr:
+        return true;
+      case Instruction::Ret:
+        return true;
+      case Instruction::BitCast:
+        return true;
+      case Instruction::Load:
+        return true;
+      case Instruction::Store:
+        return true;
+      case Instruction::Call:
+        return true;
----------------
dtcxzyw wrote:

```suggestion
      case Instruction::GetElementPtr:
      case Instruction::Ret:
      case Instruction::BitCast:
      case Instruction::Load:
      case Instruction::Store:
      case Instruction::Call:
      case Instruction::Invoke:
      case Instruction::CallBr:
        return true;
```

https://github.com/llvm/llvm-project/pull/98802


More information about the llvm-commits mailing list