[llvm] Reland "[InstCombine] Fold (sub nuw X, (Y << nuw Z)) >>u exact Z --> (X >>u exact Z) sub nuw Y" (PR #93571)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 09:26:26 PDT 2024
================
@@ -1271,6 +1271,17 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
return NewSub;
}
+ // (sub nuw X, (Y << nuw Z)) >>u exact Z --> (X >>u exact Z) sub nuw Y
+ if (I.isExact() &&
+ match(Op0, m_OneUse(m_NUWSub(m_Value(X),
+ m_NUWShl(m_Value(Y), m_Specific(Op1)))))) {
+ Value *NewLshr = Builder.CreateLShr(X, Op1, "", /*isExact=*/true);
+ auto *NewSub = BinaryOperator::CreateNUWSub(NewLshr, Y);
+ NewSub->setHasNoSignedWrap(
----------------
dtcxzyw wrote:
Please provide alive2 proof for nsw flag propagation.
https://github.com/llvm/llvm-project/pull/93571
More information about the llvm-commits
mailing list