[llvm] IR: introduce struct with CmpInst::Predicate and samesign (PR #116867)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 14:14:11 PST 2024
================
@@ -0,0 +1,40 @@
+//===- 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. The getCmpPredicate() family of
+/// functions in ICmpInst construct and return this type. It is also implictly
+/// constructed with a Predicate, dropping samesign information.
+class CmpPredicate {
+ CmpInst::Predicate Pred;
+ bool HasSameSign;
+
+public:
+ CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign = false)
+ : Pred(Pred), HasSameSign(HasSameSign) {}
+
+ operator CmpInst::Predicate() { return Pred; }
+
+ bool hasSameSign() {
+ assert(CmpInst::isIntPredicate(Pred));
+ return HasSameSign;
+ }
----------------
artagnon wrote:
Sorry, I think the EXPECT_EQ in GTEST made me believe that it would fail to compile. In fact, it just compares predicates without samesign. I think adding a smarter operator== would give us some optimizations for free, but silently (without test changes, since very few samesign tests have been written). I think it would be best to leave out operator== in this patch, in the interest of not making functional changes, and add a smart operator== in a follow-up patch, along with tests.
https://github.com/llvm/llvm-project/pull/116867
More information about the llvm-commits
mailing list