[llvm] [InstCombine] Fold `umax/umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax/umin(x, y))` and `umax/umin(nuw_shl(x, z), nuw_shl(y, z)) -> nuw_shl(umax/umin(x, y), z)` (PR #131076)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 14 05:01:55 PDT 2025
- Previous message: [llvm] [InstCombine] Fold `umax/umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax/umin(x, y))` and `umax/umin(nuw_shl(x, z), nuw_shl(y, z)) -> nuw_shl(umax/umin(x, y), z)` (PR #131076)
- Next message: [llvm] [InstCombine] Fold `umax/umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax/umin(x, y))` and `umax/umin(nuw_shl(x, z), nuw_shl(y, z)) -> nuw_shl(umax/umin(x, y), z)` (PR #131076)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
================
@@ -1592,29 +1596,34 @@ foldIntrinsicUsingDistributiveLaws(IntrinsicInst *II,
if (!leftDistributesOverRight(InnerOpcode, HasNUW, HasNSW, TopLevelOpcode))
return nullptr;
- assert(II->isCommutative() && Op0->isCommutative() &&
- "Only inner and outer commutative op codes are supported.");
-
Value *A = Op0->getOperand(0);
Value *B = Op0->getOperand(1);
Value *C = Op1->getOperand(0);
Value *D = Op1->getOperand(1);
- // Attempts to swap variables such that A always equals C
- if (A != C && A != D)
- std::swap(A, B);
- if (A == C || A == D) {
- if (A != C)
- std::swap(C, D);
+ // Attempts to swap variables such that A equals C or B equals D,
+ // if the inner operation is commutative.
+ if (Op0->isCommutative() && A != C && B != D && A == D)
+ std::swap(C, D);
+
+ if (A != C && B != D)
+ return nullptr;
----------------
nikic wrote:
nit: I'd make this an `else { return nullptr }` on the checks below instead.
https://github.com/llvm/llvm-project/pull/131076
- Previous message: [llvm] [InstCombine] Fold `umax/umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax/umin(x, y))` and `umax/umin(nuw_shl(x, z), nuw_shl(y, z)) -> nuw_shl(umax/umin(x, y), z)` (PR #131076)
- Next message: [llvm] [InstCombine] Fold `umax/umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax/umin(x, y))` and `umax/umin(nuw_shl(x, z), nuw_shl(y, z)) -> nuw_shl(umax/umin(x, y), z)` (PR #131076)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the llvm-commits
mailing list