[llvm] [LLParser] Remove unnecessary switch from the handling of the remaini… (PR #67362)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 12:48:31 PDT 2023


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/67362

…ng binary constantexprs.

FP binary operators aren't supported anymore, so we don't need a switch to pick whether we expect an integer or FP type.

>From ac043a71d8c2166c66675d6fb50ccdaba8152433 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 25 Sep 2023 12:46:27 -0700
Subject: [PATCH] [LLParser] Remove unnecessary switch from the handling of the
 remaining binary constantexprs.

FP binary operators aren't supported anymore, so we don't need a
switch to pick whether we expect an integer or FP type.
---
 llvm/lib/AsmParser/LLParser.cpp | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f1f0cdf746ee12a..a451aa508a55577 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3933,30 +3933,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
     if (Val0->getType() != Val1->getType())
       return error(ID.Loc, "operands of constexpr must have same type");
     // Check that the type is valid for the operator.
-    switch (Opc) {
-    case Instruction::Add:
-    case Instruction::Sub:
-    case Instruction::Mul:
-    case Instruction::UDiv:
-    case Instruction::SDiv:
-    case Instruction::URem:
-    case Instruction::SRem:
-    case Instruction::Shl:
-    case Instruction::AShr:
-    case Instruction::LShr:
-      if (!Val0->getType()->isIntOrIntVectorTy())
-        return error(ID.Loc, "constexpr requires integer operands");
-      break;
-    case Instruction::FAdd:
-    case Instruction::FSub:
-    case Instruction::FMul:
-    case Instruction::FDiv:
-    case Instruction::FRem:
-      if (!Val0->getType()->isFPOrFPVectorTy())
-        return error(ID.Loc, "constexpr requires fp operands");
-      break;
-    default: llvm_unreachable("Unknown binary operator!");
-    }
+    if (!Val0->getType()->isIntOrIntVectorTy())
+      return error(ID.Loc, "constexpr requires integer operands");
     unsigned Flags = 0;
     if (NUW)   Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
     if (NSW)   Flags |= OverflowingBinaryOperator::NoSignedWrap;



More information about the llvm-commits mailing list