[llvm] 2be8bea - Revert "[InstCombine] Add reverse of ((X << nuw Z) sub nuw Y) >>u exact Z --> X sub nuw (Y >>u exact Z) (#91386)"

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun May 26 23:32:51 PDT 2024


Author: Nikita Popov
Date: 2024-05-27T08:28:35+02:00
New Revision: 2be8bea1b7bbd16f745d690940b1244bf9ac4233

URL: https://github.com/llvm/llvm-project/commit/2be8bea1b7bbd16f745d690940b1244bf9ac4233
DIFF: https://github.com/llvm/llvm-project/commit/2be8bea1b7bbd16f745d690940b1244bf9ac4233.diff

LOG: Revert "[InstCombine] Add reverse of ((X << nuw Z) sub nuw Y) >>u exact Z --> X sub nuw (Y >>u exact Z) (#91386)"

This reverts commit c42c32088bdb03e39ed24f4800a447d4cbb788f2.

PR merged without review.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
    llvm/test/Transforms/InstCombine/lshr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 01b1736ae5af8..4f91993750fd2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -1275,17 +1275,6 @@ 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(
-        cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap());
-    return NewSub;
-  }
-
   auto isSuitableBinOpcode = [](Instruction::BinaryOps BinOpcode) {
     switch (BinOpcode) {
     default:

diff  --git a/llvm/test/Transforms/InstCombine/lshr.ll b/llvm/test/Transforms/InstCombine/lshr.ll
index 8ff2299db6c18..dfdb6c7b4b268 100644
--- a/llvm/test/Transforms/InstCombine/lshr.ll
+++ b/llvm/test/Transforms/InstCombine/lshr.ll
@@ -466,33 +466,6 @@ define i32 @shl_sub_lshr(i32 %x, i32 %c, i32 %y) {
   ret i32 %lshr
 }
 
-define i32 @shl_sub_lshr_reverse(i32 %x, i32 %c, i32 %y) {
-; CHECK-LABEL: @shl_sub_lshr_reverse(
-; CHECK-NEXT:    [[TMP1:%.*]] = lshr exact i32 [[Y:%.*]], [[C:%.*]]
-; CHECK-NEXT:    [[LSHR:%.*]] = sub nuw nsw i32 [[TMP1]], [[X:%.*]]
-; CHECK-NEXT:    ret i32 [[LSHR]]
-;
-  %shl = shl nuw i32 %x, %c
-  %sub = sub nuw nsw i32 %y, %shl
-  %lshr = lshr exact i32 %sub, %c
-  ret i32 %lshr
-}
-
-; Negative test
-
-define i32 @shl_sub_lshr_reverse_no_exact(i32 %x, i32 %c, i32 %y) {
-; CHECK-LABEL: @shl_sub_lshr_reverse_no_exact(
-; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
-; CHECK-NEXT:    [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
-; CHECK-NEXT:    [[LSHR:%.*]] = lshr i32 [[SUB]], [[C]]
-; CHECK-NEXT:    ret i32 [[LSHR]]
-;
-  %shl = shl nuw i32 %x, %c
-  %sub = sub nuw nsw i32 %y, %shl
-  %lshr = lshr i32 %sub, %c
-  ret i32 %lshr
-}
-
 define i32 @shl_or_lshr(i32 %x, i32 %c, i32 %y) {
 ; CHECK-LABEL: @shl_or_lshr(
 ; CHECK-NEXT:    [[TMP1:%.*]] = lshr i32 [[Y:%.*]], [[C:%.*]]


        


More information about the llvm-commits mailing list