[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:39:42 PST 2024


================
@@ -728,6 +728,24 @@ class CmpInst : public Instruction {
           InsertPosition InsertBefore = nullptr,
           Instruction *FlagsSource = nullptr);
 
+  /// Return the signed version of the predicate: variant that operates on
+  /// Predicate; used by the corresponding function in ICmpInst, to operate with
+  /// CmpPredicate.
+  static Predicate getSignedPredicate(Predicate Pred);
+
+  /// Return the unsigned version of the predicate: variant that operates on
+  /// Predicate; used by the corresponding function in ICmpInst, to operate with
+  /// CmpPredicate.
+  static Predicate getUnsignedPredicate(Predicate Pred);
+
+  /// Return the unsigned version of the signed predicate pred or the signed
+  /// version of the signed predicate pred: variant that operates on Predicate;
+  /// used by the corresponding function in ICmpInst, to operate with
+  /// CmpPredicate.
+  static Predicate getFlippedSignednessPredicate(Predicate Pred);
----------------
artagnon wrote:

I initially thought I'd make the Predicate versions of the functions local to Instructions.cpp and use it in the CmpPredicate versions in CmpPredicate.h, but realized that we can never inline calls to these functions in CmpPredicate.h (so, for example calling ICmpInst::getFlippedSignednessPredicate in CmpPredicate.h is impossible), since Instructions.h includes CmpPredicate.h, and it would create an include-cycle. Either we decide that we should never inline calls to getFlippedSignednessPredicate() in the header (but this could be a compile-time regression), or we decide to have the Predicate versions of these functions as protected members of CmpInst, as I've done.

https://github.com/llvm/llvm-project/pull/116867


More information about the llvm-commits mailing list