[llvm] llvm-reduce: Fix losing fast math flags in operands-to-args (PR #133421)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 29 02:15:05 PDT 2025
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133421
>From 0f3aa742b74ed788d9ae85421a1981e85e0e5cee Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Mar 2025 18:00:05 +0700
Subject: [PATCH] llvm-reduce: Fix losing fast math flags in operands-to-args
---
.../operands-to-args-preserve-fmf.ll | 20 +++++++++++++++++++
.../deltas/ReduceOperandsToArgs.cpp | 4 ++++
2 files changed, 24 insertions(+)
create mode 100644 llvm/test/tools/llvm-reduce/operands-to-args-preserve-fmf.ll
diff --git a/llvm/test/tools/llvm-reduce/operands-to-args-preserve-fmf.ll b/llvm/test/tools/llvm-reduce/operands-to-args-preserve-fmf.ll
new file mode 100644
index 0000000000000..b4b19ca28dbb5
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/operands-to-args-preserve-fmf.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-reduce %s -o %t --abort-on-invalid-reduction --delta-passes=operands-to-args --test FileCheck --test-arg %s --test-arg --check-prefix=INTERESTING --test-arg --input-file
+; RUN: FileCheck %s --input-file %t --check-prefix=REDUCED
+
+; INTERESTING-LABEL: define float @callee(
+; INTERESTING: fadd float
+define float @callee(float %a) {
+ %x = fadd float %a, 1.0
+ ret float %x
+}
+
+; INTERESTING-LABEL: define float @caller(
+; INTERESTING: load float
+
+; REDUCED-LABEL: define float @caller(ptr %ptr, float %val, float %callee.ret1) {
+; REDUCED: %callee.ret12 = call nnan nsz float @callee(float %val, float 0.000000e+00)
+define float @caller(ptr %ptr) {
+ %val = load float, ptr %ptr
+ %callee.ret = call nnan nsz float @callee(float %val)
+ ret float %callee.ret
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
index b9e07f2c9f63c..e1c1c9c7372f9 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
@@ -14,6 +14,7 @@
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Operator.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
@@ -107,6 +108,9 @@ static void replaceFunctionCalls(Function *OldF, Function *NewF) {
NewCI->setCallingConv(NewF->getCallingConv());
NewCI->setAttributes(CI->getAttributes());
+ if (auto *FPOp = dyn_cast<FPMathOperator>(NewCI))
+ NewCI->setFastMathFlags(CI->getFastMathFlags());
+
// Do the replacement for this use.
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
More information about the llvm-commits
mailing list