llvm-reduce: Fix losing fast math flags when removing arguments (#133408)

This commit is contained in:
Matt Arsenault 2025-03-28 23:24:49 +07:00 committed by GitHub
parent 1b86867ab3
commit 688df34634
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,26 @@
; Check that when removing arguments, existing fast math flags are preserved
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test FileCheck --test-arg --check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
; RUN: FileCheck --check-prefixes=RESULT %s < %t
; INTERESTING-LABEL: @math_callee(
define float @math_callee(float %a, float %b) {
%add = fadd float %a, %b
ret float %add
}
; INTERESTING-LABEL: @math_callee_decl(
declare float @math_callee_decl(float %a, float %b)
; INTERESTING-LABEL: @math_caller(
; INTERESTING: call
; INTERESTING: call
; RESULT: %call0 = call nnan nsz float @math_callee()
; RESULT: %call1 = call ninf float @math_callee_decl()
define float @math_caller(float %x) {
%call0 = call nnan nsz float @math_callee(float %x, float 2.0)
%call1 = call ninf float @math_callee_decl(float %x, float 2.0)
%result = fadd float %call0, %call1
ret float %result
}

View File

@ -16,8 +16,10 @@
#include "Utils.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/FMF.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Operator.h"
#include <set>
#include <vector>
@ -59,7 +61,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
}
}
// FIXME: Losing bundles, fast math flags and metadata
// FIXME: Losing bundles and metadata
CallInst *NewCI = CallInst::Create(&NewF, Args);
NewCI->setCallingConv(NewF.getCallingConv());
@ -73,6 +75,9 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
++ArgI, ++AttrIdx)
NewCI->addParamAttrs(AttrIdx, ArgAttrs[AttrIdx]);
if (auto *FPOp = dyn_cast<FPMathOperator>(NewCI))
cast<Instruction>(FPOp)->setFastMathFlags(CI->getFastMathFlags());
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
ReplaceInstWithInst(CI, NewCI);