[llvm] [IRBuilder] Fold binary intrinsics (PR #80743)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 08:01:39 PST 2024


================
@@ -1735,3 +1735,30 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
 
   return nullptr;
 }
+
+Constant *llvm::ConstantFoldBinaryIntrinsicInstruction(Intrinsic::ID ID,
+                                                       Constant *LHS,
+                                                       Constant *RHS,
+                                                       Type *Ty) {
+  auto *LC = dyn_cast<ConstantFP>(LHS);
+  if (!LC)
+    return nullptr;
+  auto *RC = dyn_cast<ConstantFP>(RHS);
+  if (!RC)
+    return nullptr;
+  auto LVal = LC->getValueAPF();
----------------
dtcxzyw wrote:

```suggestion
  const APFloat &LVal = LC->getValueAPF();
```

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


More information about the llvm-commits mailing list