[llvm] [InstCombine] Fold ((X << nuw Z) binop nuw Y) >>u Z --> X binop nuw (Y >>u Z) (PR #88193)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 19:48:33 PDT 2024


================
@@ -1259,6 +1259,54 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
       match(Op1, m_SpecificIntAllowPoison(BitWidth - 1)))
     return new ZExtInst(Builder.CreateIsNotNeg(X, "isnotneg"), Ty);
 
+  // ((X << nuw Z) sub nuw Y) >>u exact Z --> X sub nuw (Y >>u exact Z),
+  Value *Y;
+  if (I.isExact() &&
+      match(Op0, m_OneUse(m_NUWSub(m_NUWShl(m_Value(X), m_Specific(Op1)),
+                                   m_Value(Y))))) {
+    Value *NewLshr = Builder.CreateLShr(Y, Op1, "", /*isExact=*/true);
+    auto *NewSub = BinaryOperator::CreateNUWSub(X, NewLshr);
+    NewSub->setHasNoSignedWrap(
+        cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap());
+    return NewSub;
+  }
+
+  auto isSuitableBinOpcode = [](Instruction::BinaryOps BinOpcode) {
+    switch (BinOpcode) {
+    default:
+      return false;
+    case Instruction::Add:
+    case Instruction::And:
----------------
nikic wrote:

> cc @nikic @arsenm @tstellar Is there a way to revoke the approval after new changes are made to this PR?

You mean in general? Github has an option to "Dismiss stale pull request approvals when new commits are pushed", but I think this is bound to multiple layers of features we do not use (required pull requests with required approvals). It also doesn't work well with the common practice where the approval contains some final nits (usually NFC nits).

For a specific PR, you can also dismiss your old approval manually, but of course this only works if you notice the change.

https://github.com/llvm/llvm-project/pull/88193


More information about the llvm-commits mailing list