[llvm] [SelectionDAG][X86] Handle `llvm.type.test` in DAGBuilder (PR #142939)

Abhishek Kaushik via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 04:51:18 PDT 2025


================
@@ -7384,6 +7384,22 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     setValue(&I, getValue(I.getOperand(0)));
     return;
 
+  case Intrinsic::type_test:
+  case Intrinsic::public_type_test: {
+    bool AllUsersAreAssume = llvm::all_of(I.users(), [](const User *U) {
+      if (const auto *call = dyn_cast<CallInst>(U)) {
+        return call->getIntrinsicID() == Intrinsic::assume;
+      }
+      return false;
+    });
+
+    if (AllUsersAreAssume)
+      setValue(&I, DAG.getUNDEF(MVT::i1));
+    else
+      setValue(&I, DAG.getConstant(1, sdl, MVT::i1));
----------------
abhishek-kaushik22 wrote:

Wouldn't there be a problem when the value is used in branches?

```
%call = tail call i1 @llvm.type.test(ptr null, metadata !"typeinfo")
br i1 %call, label %bb2, label %bb1
```


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


More information about the llvm-commits mailing list