[llvm] IR: introduce struct with CmpInst::Predicate and samesign (PR #116867)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 28 14:42:54 PST 2024
================
@@ -1203,38 +1204,78 @@ class ICmpInst: public CmpInst {
#endif
}
+ /// @returns the predicate along with samesign information.
+ CmpPredicate getCmpPredicate() const {
+ return {getPredicate(), hasSameSign()};
+ }
+
+ /// @returns the inverse predicate along with samesign information: static
+ /// variant.
+ static CmpPredicate getInverseCmpPredicate(CmpPredicate Pred) {
+ return {getInversePredicate(Pred), Pred.hasSameSign()};
+ }
+
+ /// @returns the inverse predicate along with samesign information.
+ CmpPredicate getInverseCmpPredicate() const {
+ return getInverseCmpPredicate(getCmpPredicate());
+ }
+
+ /// @returns the swapped predicate along with samesign information: static
+ /// variant.
+ static CmpPredicate getSwappedCmpPredicate(CmpPredicate Pred) {
+ return {getSwappedPredicate(Pred), Pred.hasSameSign()};
+ }
+
+ /// @returns the swapped predicate along with samesign information.
+ CmpPredicate getSwappedCmpPredicate() const {
+ return getSwappedPredicate(getCmpPredicate());
+ }
+
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
/// @returns the predicate that would be the result if the operand were
/// regarded as signed.
- /// Return the signed version of the predicate.
- Predicate getSignedPredicate() const {
- return getSignedPredicate(getPredicate());
+ /// Return the signed version of the predicate along with samesign
+ /// information.
+ CmpPredicate getSignedPredicate() const {
+ return getSignedPredicate(getCmpPredicate());
}
- /// Return the signed version of the predicate: static variant.
- static Predicate getSignedPredicate(Predicate pred);
+ /// Return the signed version of the predicate along with samesign
+ /// information: static variant.
+ static CmpPredicate getSignedPredicate(CmpPredicate Pred) {
+ return {CmpInst::getSignedPredicate(Pred), Pred.hasSameSign()};
+ }
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
/// @returns the predicate that would be the result if the operand were
/// regarded as unsigned.
- /// Return the unsigned version of the predicate.
- Predicate getUnsignedPredicate() const {
- return getUnsignedPredicate(getPredicate());
+ /// Return the unsigned version of the predicate along with samesign
+ /// information.
+ CmpPredicate getUnsignedPredicate() const {
+ return getUnsignedPredicate(getCmpPredicate());
}
- /// Return the unsigned version of the predicate: static variant.
- static Predicate getUnsignedPredicate(Predicate pred);
+ /// Return the unsigned version of the predicate along with samesign
+ /// information: static variant.
+ static CmpPredicate getUnsignedPredicate(CmpPredicate Pred) {
+ return {CmpInst::getUnsignedPredicate(Pred), Pred.hasSameSign()};
+ }
- /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
+ /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
/// @returns the unsigned version of the signed predicate pred or
- /// the signed version of the signed predicate pred.
- static Predicate getFlippedSignednessPredicate(Predicate pred);
+ /// the signed version of the signed predicate pred, along with
+ /// samesign information.
+ /// Static variant.
+ static CmpPredicate getFlippedSignednessPredicate(CmpPredicate Pred) {
+ return {CmpInst::getFlippedSignednessPredicate(Pred), Pred.hasSameSign()};
+ }
- /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
+ /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
/// @returns the unsigned version of the signed predicate pred or
- /// the signed version of the signed predicate pred.
- Predicate getFlippedSignednessPredicate() const {
- return getFlippedSignednessPredicate(getPredicate());
+ /// the signed version of the signed predicate pred, along with
+ /// samesign information.
+ CmpPredicate getFlippedSignednessPredicate() const {
+ return getFlippedSignednessPredicate(getCmpPredicate());
----------------
artagnon wrote:
I think having ICmpInst::getPredicate() overshadow CmpInst::getPredicate() would be highly confusing and undesirable, so I think I will rename getFlippedSignednessPredicate() and friends to include a Cmp; we'd pay a small refactor-code-churn price.
https://github.com/llvm/llvm-project/pull/116867
More information about the llvm-commits
mailing list