[llvm] [InstCombine] Create Icmp in canonical form (NFC) (PR #146266)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 29 03:38:01 PDT 2025


https://github.com/andjo403 created https://github.com/llvm/llvm-project/pull/146266

Noticed that this Icmp was not created in canonical form and as the pred is either EQ or NE it is easy to move the constant to the RHS.

>From f29cd154e8a89a17b5d35f7cbd2a882a5b17230c Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Sun, 29 Jun 2025 12:26:29 +0200
Subject: [PATCH] [InstCombine] Create Icmp in canonical form (NFC)

---
 llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index dce695a036006..dd16cfaeecd45 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -681,7 +681,7 @@ static Value *foldLogOpOfMaskedICmps(Value *LHS, Value *RHS, bool IsAnd,
         }
         Value *NewAnd = Builder.CreateAnd(A, BD);
         Value *CEVal = ConstantInt::get(A->getType(), CE);
-        return Builder.CreateICmp(CC, CEVal, NewAnd);
+        return Builder.CreateICmp(CC, NewAnd, CEVal);
       };
 
       if (Mask & BMask_Mixed)



More information about the llvm-commits mailing list