Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions llvm/lib/CodeGen/MIRParser/MILexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ static Cursor maybeLexFloatHexBits(Cursor C, MIToken &Token) {
return C;
}

static Cursor maybeLexInfinityLiteral(Cursor C, MIToken &Token) {
if ((C.peek() != '+' && C.peek() != '-') || C.peek(1) != 'i' ||
C.peek(2) != 'n' || C.peek(3) != 'f' ||
isIdentifierChar(C.peek(4)))
return std::nullopt;

auto Range = C;
C.advance(4);
Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
return C;
}

static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) {
if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
return std::nullopt;
Expand Down Expand Up @@ -779,6 +791,8 @@ StringRef llvm::lexMIToken(StringRef Source, MIToken &Token,
return R.remaining();
if (Cursor R = maybeLexFloatHexBits(C, Token))
return R.remaining();
if (Cursor R = maybeLexInfinityLiteral(C, Token))
return R.remaining();
if (Cursor R = maybeLexIdentifier(C, Token))
return R.remaining();
if (Cursor R = maybeLexJumpTableIndex(C, Token))
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/MIR/Generic/fp-infinity.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# RUN: llc -run-pass none -o - %s | FileCheck %s

---
name: fp_infinity
body: |
bb.0:
; CHECK: %0:_(s32) = G_FCONSTANT float +inf
; CHECK: %1:_(s32) = G_FCONSTANT float -inf
%0:_(s32) = G_FCONSTANT float +inf
%1:_(s32) = G_FCONSTANT float -inf
...