[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 09:24:45 PDT 2024


================
@@ -4282,6 +4282,64 @@ static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) {
   CI->getParent()->insertDbgRecordBefore(DR, CI->getIterator());
 }
 
+static CallBase *upgradeConstrainedIntrinsicCall(CallBase *CB, Function *F,
+                                                 IRBuilder<> &Builder) {
+  if (CB->getOperandBundle(LLVMContext::OB_fpe_round))
+    return nullptr;
+
+  auto *CFPI = cast<ConstrainedFPIntrinsic>(F);
+  SmallVector<OperandBundleDef, 2> NewBundles;
+  LLVMContext &C = CB->getContext();
+
+  auto RM = CFPI->getRoundingMode();
+  if (RM) {
+    auto CurrentRM = CB->getRoundingMode();
+    if (CurrentRM) {
+      assert(*RM == *CurrentRM);
+    } else {
+      int RMValue = static_cast<int>(*RM);
+      NewBundles.emplace_back("fpe.round",
+                              ConstantInt::get(Type::getInt32Ty(C), RMValue));
+    }
+  }
+
+  auto EB = CFPI->getExceptionBehavior();
+  if (EB) {
+    auto CurrentEB = CB->getExceptionBehavior();
+    if (CurrentEB) {
+      assert(*EB == *CurrentEB);
+    } else {
+      NewBundles.emplace_back("fpe.except",
+                              ConstantInt::get(Type::getInt32Ty(C), *EB));
+    }
+  }
+
+  CallInst *NewCB = nullptr;
+  if (!NewBundles.empty()) {
+    SmallVector<Value *, 4> Args(CB->args());
+    SmallVector<OperandBundleDef, 2> Bundles;
----------------
spavloff wrote:

It requires change of the called function, as metadata arguments are mandatory. Eventually it should be implemented but in a subsequent patch.

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


More information about the cfe-commits mailing list