[llvm] [NFC][LLVM][FPEnv] Minor cleanup in convert to string functions (PR #195461)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Sat May 2 08:26:37 PDT 2026
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/195461
Return string value directly from the switch-case.
>From cd4c8f581ecbb63ba40b9c8ac7b6ac662bb011b4 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 2 May 2026 08:25:07 -0700
Subject: [PATCH] [NFC][LLVM][FPEnv] Minor cleanup in convert to string
functions
Return string value directly from the switch-case.
---
llvm/lib/IR/FPEnv.cpp | 34 +++++++++++-----------------------
1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/llvm/lib/IR/FPEnv.cpp b/llvm/lib/IR/FPEnv.cpp
index c41d7b3181a37..f19c11b2a35d4 100644
--- a/llvm/lib/IR/FPEnv.cpp
+++ b/llvm/lib/IR/FPEnv.cpp
@@ -37,30 +37,22 @@ llvm::convertStrToRoundingMode(StringRef RoundingArg) {
std::optional<StringRef>
llvm::convertRoundingModeToStr(RoundingMode UseRounding) {
- std::optional<StringRef> RoundingStr;
switch (UseRounding) {
case RoundingMode::Dynamic:
- RoundingStr = "round.dynamic";
- break;
+ return "round.dynamic";
case RoundingMode::NearestTiesToEven:
- RoundingStr = "round.tonearest";
- break;
+ return "round.tonearest";
case RoundingMode::NearestTiesToAway:
- RoundingStr = "round.tonearestaway";
- break;
+ return "round.tonearestaway";
case RoundingMode::TowardNegative:
- RoundingStr = "round.downward";
- break;
+ return "round.downward";
case RoundingMode::TowardPositive:
- RoundingStr = "round.upward";
- break;
+ return "round.upward";
case RoundingMode::TowardZero:
- RoundingStr = "round.towardzero";
- break;
+ return "round.towardzero";
default:
- break;
+ return std::nullopt;
}
- return RoundingStr;
}
std::optional<fp::ExceptionBehavior>
@@ -74,19 +66,15 @@ llvm::convertStrToExceptionBehavior(StringRef ExceptionArg) {
std::optional<StringRef>
llvm::convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
- std::optional<StringRef> ExceptStr;
switch (UseExcept) {
case fp::ebStrict:
- ExceptStr = "fpexcept.strict";
- break;
+ return "fpexcept.strict";
case fp::ebIgnore:
- ExceptStr = "fpexcept.ignore";
- break;
+ return "fpexcept.ignore";
case fp::ebMayTrap:
- ExceptStr = "fpexcept.maytrap";
- break;
+ return "fpexcept.maytrap";
}
- return ExceptStr;
+ return std::nullopt;
}
Intrinsic::ID llvm::getConstrainedIntrinsicID(const Instruction &Instr) {
More information about the llvm-commits
mailing list