[llvm] [IR] Add `samesign` flag to icmp instruction (PR #111419)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 12:34:09 PDT 2024


================
@@ -1033,6 +1033,28 @@ class CmpInst : public Instruction {
   }
 };
 
+/// An icmp instruction, which can be marked as "samesign", indicating that the
+/// two operands have the same sign. This means that we can convert "slt/ult"
+/// to "ult", which enables more optimizations.
+class PossiblySameSignInst : public CmpInst {
+public:
+  enum { SameSign = (1 << 0) };
+
+  void setSameSign(bool B) {
+    SubclassOptionalData = (SubclassOptionalData & ~SameSign) | (B * SameSign);
+  }
+
+  bool hasSameSign() const { return SubclassOptionalData & SameSign; }
+
+  static bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::ICmp;
+  }
+
+  static bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
----------------
tschuett wrote:

isa + cast -> dyn_cast

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


More information about the llvm-commits mailing list