[llvm] IR: introduce struct with CmpInst::Predicate and samesign (PR #116867)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 3 02:59:21 PST 2024
================
@@ -0,0 +1,62 @@
+//===- CmpPredicate.h - CmpInst Predicate with samesign information -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A CmpInst::Predicate with any samesign information (applicable to ICmpInst).
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_CMPPREDICATE_H
+#define LLVM_IR_CMPPREDICATE_H
+
+#include "llvm/IR/InstrTypes.h"
+
+namespace llvm {
+/// An abstraction over a floating-point predicate, and a pack of an integer
+/// predicate with samesign information. Some functions in ICmpInst construct
+/// and return this type in place of a Predicate.
+class CmpPredicate {
+ CmpInst::Predicate Pred;
+ bool HasSameSign;
+
+public:
+ // Constructed implictly with a either Predicate and samesign information, or
+ // just a Predicate, dropping samesign information.
+ CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign = false)
+ : Pred(Pred), HasSameSign(HasSameSign) {
+ assert(!HasSameSign || CmpInst::isIntPredicate(Pred));
+ }
+
+ // Implictly converts to the underlying Predicate, dropping samesign
+ // information.
+ operator CmpInst::Predicate() const { return Pred; }
+
+ // Query samesign information, for optimizations.
----------------
nikic wrote:
```suggestion
/// Query samesign information, for optimizations.
```
etc
https://github.com/llvm/llvm-project/pull/116867
More information about the llvm-commits
mailing list