[clang] [CIR] Add noundef to memchr declaration and call sites (PR #191457)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 10 15:20:25 PDT 2026


================
@@ -4688,10 +4670,25 @@ mlir::LogicalResult CIRToLLVMMemChrOpLowering::matchAndRewrite(
                                         /*isVarArg=*/false);
   llvm::StringRef fnName = "memchr";
   createLLVMFuncOpIfNotExist(rewriter, op, fnName, fnTy);
-  rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
+
+  mlir::Builder b(rewriter.getContext());
+  auto noundefAttr = b.getNamedAttr("llvm.noundef", b.getUnitAttr());
+  auto noundefDict = mlir::DictionaryAttr::get(rewriter.getContext(),
+                                               llvm::ArrayRef(noundefAttr));
+  SmallVector<mlir::Attribute> argAttrs(3, noundefDict);
+  auto argAttrsArr = mlir::ArrayAttr::get(rewriter.getContext(), argAttrs);
+
+  auto modOp = op->getParentOfType<mlir::ModuleOp>();
+  if (auto fn = mlir::dyn_cast_or_null<mlir::LLVM::LLVMFuncOp>(
+          mlir::SymbolTable::lookupSymbolIn(modOp, fnName)))
----------------
andykaylor wrote:

This is a pretty expensive thing to do every time we call this function. You should probably be doing this in `createLLVMFuncOpIfNotExist` instead.

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


More information about the cfe-commits mailing list