[llvm] Min and Max are associative (PR #82621)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 05:58:55 PST 2024


https://github.com/natanelh-mobileye created https://github.com/llvm/llvm-project/pull/82621

Min and Max are associative

>From 233083382d1b3f0b2925af1096cf50555728e01e Mon Sep 17 00:00:00 2001
From: natanelh-mobileye <155897558+natanelh-mobileye at users.noreply.github.com>
Date: Thu, 22 Feb 2024 15:58:00 +0200
Subject: [PATCH] Min and Max are associative

---
 llvm/include/llvm/IR/Instruction.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index c0e159a342d5b5..1b71448fce3f8e 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -668,12 +668,13 @@ class Instruction : public User,
   ///
   ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
   ///
-  /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
+  /// In LLVM, the Add, Mul, And, Or, Xor, Min and Max operators are associative.
   ///
   bool isAssociative() const LLVM_READONLY;
   static bool isAssociative(unsigned Opcode) {
     return Opcode == And || Opcode == Or || Opcode == Xor ||
-           Opcode == Add || Opcode == Mul;
+           Opcode == Add || Opcode == Mul || Opcode == Min ||
+           Opcode == Max;
   }
 
   /// Return true if the instruction is commutative:



More information about the llvm-commits mailing list