Skip to content

Conversation

@andjo403
Copy link
Contributor

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.

@andjo403 andjo403 requested a review from nikic as a code owner June 29, 2025 10:37
@andjo403 andjo403 requested review from dtcxzyw and nikic and removed request for nikic June 29, 2025 10:38
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Jun 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 29, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Andreas Jonson (andjo403)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/146266.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+1-1)
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)

@andjo403 andjo403 merged commit f21f2b4 into llvm:main Jun 29, 2025
10 checks passed
@andjo403 andjo403 deleted the canonicalIcmpCreate branch June 29, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants