[llvm] [InstCombine] Fold `(X & Mask) == 0 ? TC : FC -> TC binop (X & Mask)` (PR #100437)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 01:43:31 PDT 2024
================
@@ -186,6 +186,22 @@ static Value *foldSelectICmpAnd(SelectInst &Sel, ICmpInst *Cmp,
return ExtraBitInTC ? Builder.CreateXor(V, C) : Builder.CreateOr(V, C);
}
+ // (V & AndMaskC) == 0 ? TC : FC --> (V & AndMaskC) + TC
+ if (TC + AndMask == FC) {
+ if (CreateAnd)
+ V = Builder.CreateAnd(V, ConstantInt::get(SelType, AndMask));
+ Constant *C = ConstantInt::get(SelType, TC);
+ return Builder.CreateAdd(V, C);
+ }
+
+ // (V & AndMaskC) == 0 ? TC : FC --> TC - (V & AndMaskC)
+ if (TC - AndMask == FC) {
+ if (CreateAnd)
+ V = Builder.CreateAnd(V, ConstantInt::get(SelType, AndMask));
+ Constant *C = ConstantInt::get(SelType, TC);
+ return Builder.CreateSub(C, V);
+ }
----------------
dtcxzyw wrote:
Before: http://llvm-compile-time-tracker.com/compare.php?from=fbd303ba5dd98d4513d62058bc1ad463507464ce&to=9f108f5a9cd6645212efdfff325eb484171799ab&stat=instructions%3Au
https://github.com/llvm/llvm-project/pull/100437
More information about the llvm-commits
mailing list