[llvm] [LLParser] Merge xor constantexpr parsing with add/mul/shl/lshr/ashr. (PR #67371)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 25 14:13:39 PDT 2023
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/67371
Not sure if xor is sticking around or not. I see and/or was already removed.
This changes the error messages and makes one error message more accurate.
>From 218b6756e7073b9316909a415852a3da4e9dec86 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 25 Sep 2023 14:09:10 -0700
Subject: [PATCH] [LLParser] Merge xor constantexpr parsing with
add/mul/shl/lshr/ashr.
Not sure if xor is sticking around or not. I see and/or was already removed.
This changes the error messages and makes one error message more accurate.
---
llvm/lib/AsmParser/LLParser.cpp | 30 ++++---------------
.../2003-05-21-MalformedShiftCrash.ll | 2 +-
2 files changed, 6 insertions(+), 26 deletions(-)
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index a451aa508a55577..04eabc94cfc6abe 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3903,7 +3903,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
case lltok::kw_mul:
case lltok::kw_shl:
case lltok::kw_lshr:
- case lltok::kw_ashr: {
+ case lltok::kw_ashr:
+ case lltok::kw_xor: {
bool NUW = false;
bool NSW = false;
bool Exact = false;
@@ -3934,34 +3935,13 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return error(ID.Loc, "operands of constexpr must have same type");
// Check that the type is valid for the operator.
if (!Val0->getType()->isIntOrIntVectorTy())
- return error(ID.Loc, "constexpr requires integer operands");
+ return error(ID.Loc,
+ "constexpr requires integer or integer vector operands");
unsigned Flags = 0;
if (NUW) Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
if (NSW) Flags |= OverflowingBinaryOperator::NoSignedWrap;
if (Exact) Flags |= PossiblyExactOperator::IsExact;
- Constant *C = ConstantExpr::get(Opc, Val0, Val1, Flags);
- ID.ConstantVal = C;
- ID.Kind = ValID::t_Constant;
- return false;
- }
-
- // Logical Operations
- case lltok::kw_xor: {
- unsigned Opc = Lex.getUIntVal();
- Constant *Val0, *Val1;
- Lex.Lex();
- if (parseToken(lltok::lparen, "expected '(' in logical constantexpr") ||
- parseGlobalTypeAndValue(Val0) ||
- parseToken(lltok::comma, "expected comma in logical constantexpr") ||
- parseGlobalTypeAndValue(Val1) ||
- parseToken(lltok::rparen, "expected ')' in logical constantexpr"))
- return true;
- if (Val0->getType() != Val1->getType())
- return error(ID.Loc, "operands of constexpr must have same type");
- if (!Val0->getType()->isIntOrIntVectorTy())
- return error(ID.Loc,
- "constexpr requires integer or integer vector operands");
- ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1);
+ ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1, Flags);
ID.Kind = ValID::t_Constant;
return false;
}
diff --git a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
index 5b456008751285a..0ec3c8b1045cbcc 100644
--- a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
+++ b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
@@ -1,5 +1,5 @@
; Found by inspection of the code
; RUN: not llvm-as < %s > /dev/null 2> %t
-; RUN: grep "constexpr requires integer operands" %t
+; RUN: grep "constexpr requires integer or integer vector operands" %t
@0 = global i32 ashr (float 1.0, float 2.0)
More information about the llvm-commits
mailing list