-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[GlobalISel] Add constant matcher for APInt #151357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,63 +192,92 @@ m_GFCstOrSplat(std::optional<FPValueAndVReg> &FPValReg) { | |
|
|
||
| /// Matcher for a specific constant value. | ||
| struct SpecificConstantMatch { | ||
| int64_t RequestedVal; | ||
| SpecificConstantMatch(int64_t RequestedVal) : RequestedVal(RequestedVal) {} | ||
| APInt RequestedVal; | ||
| SpecificConstantMatch(APInt RequestedVal) : RequestedVal(RequestedVal) {} | ||
| bool match(const MachineRegisterInfo &MRI, Register Reg) { | ||
| int64_t MatchedVal; | ||
| return mi_match(Reg, MRI, m_ICst(MatchedVal)) && MatchedVal == RequestedVal; | ||
| APInt MatchedVal; | ||
| if (mi_match(Reg, MRI, m_ICst(MatchedVal))) { | ||
| if (MatchedVal.getBitWidth() > RequestedVal.getBitWidth()) | ||
| RequestedVal = RequestedVal.sext(MatchedVal.getBitWidth()); | ||
| else | ||
| MatchedVal = MatchedVal.sext(RequestedVal.getBitWidth()); | ||
|
|
||
| return APInt::isSameValue(MatchedVal, RequestedVal); | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /// Matches a constant equal to \p RequestedValue. | ||
| inline SpecificConstantMatch m_SpecificICst(APInt RequestedValue) { | ||
| return SpecificConstantMatch(std::move(RequestedValue)); | ||
| } | ||
|
|
||
| inline SpecificConstantMatch m_SpecificICst(int64_t RequestedValue) { | ||
| return SpecificConstantMatch(RequestedValue); | ||
| return SpecificConstantMatch(APInt(64, RequestedValue, /* isSigned */ true)); | ||
| } | ||
|
|
||
| /// Matcher for a specific constant splat. | ||
| struct SpecificConstantSplatMatch { | ||
| int64_t RequestedVal; | ||
| SpecificConstantSplatMatch(int64_t RequestedVal) | ||
| : RequestedVal(RequestedVal) {} | ||
| APInt RequestedVal; | ||
| SpecificConstantSplatMatch(APInt RequestedVal) : RequestedVal(RequestedVal) {} | ||
| bool match(const MachineRegisterInfo &MRI, Register Reg) { | ||
| return isBuildVectorConstantSplat(Reg, MRI, RequestedVal, | ||
| /* AllowUndef */ false); | ||
| } | ||
| }; | ||
|
|
||
| /// Matches a constant splat of \p RequestedValue. | ||
| inline SpecificConstantSplatMatch m_SpecificICstSplat(APInt RequestedValue) { | ||
| return SpecificConstantSplatMatch(std::move(RequestedValue)); | ||
| } | ||
|
|
||
| inline SpecificConstantSplatMatch m_SpecificICstSplat(int64_t RequestedValue) { | ||
| return SpecificConstantSplatMatch(RequestedValue); | ||
| return SpecificConstantSplatMatch( | ||
| APInt(64, RequestedValue, /* isSigned */ true)); | ||
| } | ||
|
|
||
| /// Matcher for a specific constant or constant splat. | ||
| struct SpecificConstantOrSplatMatch { | ||
| int64_t RequestedVal; | ||
| SpecificConstantOrSplatMatch(int64_t RequestedVal) | ||
| APInt RequestedVal; | ||
| SpecificConstantOrSplatMatch(APInt RequestedVal) | ||
| : RequestedVal(RequestedVal) {} | ||
| bool match(const MachineRegisterInfo &MRI, Register Reg) { | ||
| int64_t MatchedVal; | ||
| if (mi_match(Reg, MRI, m_ICst(MatchedVal)) && MatchedVal == RequestedVal) | ||
| return true; | ||
| APInt MatchedVal; | ||
| if (mi_match(Reg, MRI, m_ICst(MatchedVal))) { | ||
| if (MatchedVal.getBitWidth() > RequestedVal.getBitWidth()) | ||
| RequestedVal = RequestedVal.sext(MatchedVal.getBitWidth()); | ||
| else | ||
| MatchedVal = MatchedVal.sext(RequestedVal.getBitWidth()); | ||
|
|
||
| if (APInt::isSameValue(MatchedVal, RequestedVal)) | ||
| return true; | ||
| } | ||
| return isBuildVectorConstantSplat(Reg, MRI, RequestedVal, | ||
| /* AllowUndef */ false); | ||
| } | ||
| }; | ||
|
|
||
| /// Matches a \p RequestedValue constant or a constant splat of \p | ||
| /// RequestedValue. | ||
| inline SpecificConstantOrSplatMatch | ||
| m_SpecificICstOrSplat(APInt RequestedValue) { | ||
| return SpecificConstantOrSplatMatch(std::move(RequestedValue)); | ||
| } | ||
|
|
||
| inline SpecificConstantOrSplatMatch | ||
| m_SpecificICstOrSplat(int64_t RequestedValue) { | ||
| return SpecificConstantOrSplatMatch(RequestedValue); | ||
| return SpecificConstantOrSplatMatch( | ||
| APInt(64, RequestedValue, /* isSigned */ true)); | ||
| } | ||
|
|
||
| ///{ | ||
| /// Convenience matchers for specific integer values. | ||
| inline SpecificConstantMatch m_ZeroInt() { return SpecificConstantMatch(0); } | ||
| inline SpecificConstantMatch m_ZeroInt() { | ||
| return SpecificConstantMatch(APInt(64, 0)); | ||
|
||
| } | ||
| inline SpecificConstantMatch m_AllOnesInt() { | ||
| return SpecificConstantMatch(-1); | ||
| return SpecificConstantMatch(APInt(64, -1, /* isSigned */ true)); | ||
|
||
| } | ||
| ///} | ||
|
|
||
| /// Matcher for a specific register. | ||
| struct SpecificRegisterMatch { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ref