[llvm] d3d4a24 - llvm-reduce: Fix losing fast math flags in operands-to-args (#133421)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 29 02:17:46 PDT 2025
Author: Matt Arsenault
Date: 2025-03-29T16:17:43+07:00
New Revision: d3d4a242de047f41589b4e2a27ecbcc3273d4cbf
URL: https://github.com/llvm/llvm-project/commit/d3d4a242de047f41589b4e2a27ecbcc3273d4cbf
DIFF: https://github.com/llvm/llvm-project/commit/d3d4a242de047f41589b4e2a27ecbcc3273d4cbf.diff
LOG: llvm-reduce: Fix losing fast math flags in operands-to-args (#133421)
Added:
llvm/test/tools/llvm-reduce/operands-to-args-preserve-fmf.ll
Modified:
llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
Removed:
################################################################################
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