Skip to content

Commit 9753074

Browse files
committed
Simplify code
1 parent 8978fe6 commit 9753074

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ Value *emitUnaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
576576
// Depending on mode, this may be a constrained floating-point intrinsic.
577577
static Value *emitBinaryMaybeConstrainedFPBuiltin(
578578
CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID,
579-
unsigned ConstrainedIntrinsicID, llvm::FastMathFlags *FMF = nullptr) {
579+
unsigned ConstrainedIntrinsicID,
580+
llvm::FastMathFlags FMF = llvm::FastMathFlags()) {
580581
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
581582
llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
582583

@@ -587,7 +588,10 @@ static Value *emitBinaryMaybeConstrainedFPBuiltin(
587588
std::nullopt, std::nullopt, FMF);
588589
} else {
589590
Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
590-
return CGF.Builder.CreateCall(F, {Src0, Src1}, "", nullptr, FMF);
591+
CallInst *CI = CGF.Builder.CreateCall(F, {Src0, Src1});
592+
if (isa<FPMathOperator>(CI))
593+
CI->setFastMathFlags(FMF);
594+
return CI;
591595
}
592596
}
593597

@@ -2618,7 +2622,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
26182622
FMF.setNoSignedZeros();
26192623
return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
26202624
*this, E, Intrinsic::maxnum,
2621-
Intrinsic::experimental_constrained_maxnum, &FMF));
2625+
Intrinsic::experimental_constrained_maxnum, FMF));
26222626
}
26232627

26242628
case Builtin::BIfmin:
@@ -2633,7 +2637,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
26332637
FMF.setNoSignedZeros();
26342638
return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
26352639
*this, E, Intrinsic::minnum,
2636-
Intrinsic::experimental_constrained_minnum, &FMF));
2640+
Intrinsic::experimental_constrained_minnum, FMF));
26372641
}
26382642

26392643
case Builtin::BIfmaximum_num:

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,14 +2491,12 @@ class IRBuilderBase {
24912491
public:
24922492
CallInst *CreateCall(FunctionType *FTy, Value *Callee,
24932493
ArrayRef<Value *> Args = {}, const Twine &Name = "",
2494-
MDNode *FPMathTag = nullptr,
2495-
FastMathFlags *uFMF = nullptr) {
2494+
MDNode *FPMathTag = nullptr) {
24962495
CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
24972496
if (IsFPConstrained)
24982497
setConstrainedFPCallAttr(CI);
2499-
if (isa<FPMathOperator>(CI)) {
2500-
setFPAttrs(CI, FPMathTag, uFMF ? (FMF | *uFMF) : FMF);
2501-
}
2498+
if (isa<FPMathOperator>(CI))
2499+
setFPAttrs(CI, FPMathTag, FMF);
25022500
return Insert(CI, Name);
25032501
}
25042502

@@ -2514,10 +2512,9 @@ class IRBuilderBase {
25142512
}
25152513

25162514
CallInst *CreateCall(FunctionCallee Callee, ArrayRef<Value *> Args = {},
2517-
const Twine &Name = "", MDNode *FPMathTag = nullptr,
2518-
FastMathFlags *uFMF = nullptr) {
2515+
const Twine &Name = "", MDNode *FPMathTag = nullptr) {
25192516
return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2520-
FPMathTag, uFMF);
2517+
FPMathTag);
25212518
}
25222519

25232520
CallInst *CreateCall(FunctionCallee Callee, ArrayRef<Value *> Args,
@@ -2531,7 +2528,7 @@ class IRBuilderBase {
25312528
Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
25322529
std::optional<RoundingMode> Rounding = std::nullopt,
25332530
std::optional<fp::ExceptionBehavior> Except = std::nullopt,
2534-
FastMathFlags *FMF = nullptr);
2531+
FastMathFlags newFMF = FastMathFlags());
25352532

25362533
Value *CreateSelect(Value *C, Value *True, Value *False,
25372534
const Twine &Name = "", Instruction *MDFrom = nullptr);

llvm/lib/IR/IRBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,15 +1082,17 @@ CallInst *IRBuilderBase::CreateConstrainedFPCmp(
10821082
CallInst *IRBuilderBase::CreateConstrainedFPCall(
10831083
Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
10841084
std::optional<RoundingMode> Rounding,
1085-
std::optional<fp::ExceptionBehavior> Except, FastMathFlags *FMF) {
1085+
std::optional<fp::ExceptionBehavior> Except, FastMathFlags newFMF) {
10861086
llvm::SmallVector<Value *, 6> UseArgs(Args);
10871087

10881088
if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
10891089
UseArgs.push_back(getConstrainedFPRounding(Rounding));
10901090
UseArgs.push_back(getConstrainedFPExcept(Except));
10911091

1092-
CallInst *C = CreateCall(Callee, UseArgs, Name, nullptr, FMF);
1092+
CallInst *C = CreateCall(Callee, UseArgs, Name);
10931093
setConstrainedFPCallAttr(C);
1094+
if (isa<FPMathOperator>(C))
1095+
C->setFastMathFlags(newFMF);
10941096
return C;
10951097
}
10961098

0 commit comments

Comments
 (0)