[llvm] r358026 - Revert "[InstCombine] [InstCombine] Canonicalize (-X s/ Y) to -(X s/ Y)."

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 11:32:39 PDT 2019


Author: nikic
Date: Tue Apr  9 11:32:38 2019
New Revision: 358026

URL: http://llvm.org/viewvc/llvm-project?rev=358026&view=rev
Log:
Revert "[InstCombine] [InstCombine] Canonicalize (-X s/ Y) to -(X s/ Y)."

This reverts commit 1383a9168948aabfd827220c9445ce0ce5765800.

sdiv-canonicalize.ll fails after this revision. The fold needs to be
moved outside the branch handling constant operands. However when this
is done there are further test changes, so I'm reverting this in the
meantime.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/sdiv-canonicalize.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=358026&r1=358025&r2=358026&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Tue Apr  9 11:32:38 2019
@@ -1043,12 +1043,6 @@ Instruction *InstCombiner::visitSDiv(Bin
       Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
       return new SExtInst(NarrowOp, Op0->getType());
     }
-  
-  // -X / Y --> -(X / Y)
-  Value *Y;
-  if (match(&I, m_SDiv(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y))))
-    return BinaryOperator::CreateNSWNeg(
-        Builder.CreateSDiv(X, Y, I.getName(), I.isExact()));
 
     // -X / C --> X / -C (if the negation doesn't overflow).
     // TODO: This could be enhanced to handle arbitrary vector constants by

Modified: llvm/trunk/test/Transforms/InstCombine/sdiv-canonicalize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sdiv-canonicalize.ll?rev=358026&r1=358025&r2=358026&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sdiv-canonicalize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sdiv-canonicalize.ll Tue Apr  9 11:32:38 2019
@@ -3,8 +3,8 @@
 
 define i32 @test_sdiv_canonicalize_op0(i32 %x, i32 %y) {
 ; CHECK-LABEL: @test_sdiv_canonicalize_op0(
-; CHECK-NEXT:    [[SDIV1:%.*]] = sdiv i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[SDIV:%.*]] = sub nsw i32 0, [[SDIV1]]
+; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
+; CHECK-NEXT:    [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i32 [[SDIV]]
 ;
   %neg = sub nsw i32 0, %x
@@ -14,8 +14,8 @@ define i32 @test_sdiv_canonicalize_op0(i
 
 define i32 @test_sdiv_canonicalize_op0_exact(i32 %x, i32 %y) {
 ; CHECK-LABEL: @test_sdiv_canonicalize_op0_exact(
-; CHECK-NEXT:    [[SDIV1:%.*]] = sdiv exact i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[SDIV:%.*]] = sub nsw i32 0, [[SDIV1]]
+; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
+; CHECK-NEXT:    [[SDIV:%.*]] = sdiv exact i32 [[NEG]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i32 [[SDIV]]
 ;
   %neg = sub nsw i32 0, %x
@@ -23,7 +23,6 @@ define i32 @test_sdiv_canonicalize_op0_e
   ret i32 %sdiv
 }
 
-; (X/-Y) is not equal to -(X/Y), don't canonicalize.
 define i32 @test_sdiv_canonicalize_op1(i32 %x, i32 %z) {
 ; CHECK-LABEL: @test_sdiv_canonicalize_op1(
 ; CHECK-NEXT:    [[Y:%.*]] = mul i32 [[Z:%.*]], 3
@@ -50,8 +49,8 @@ define i32 @test_sdiv_canonicalize_nonsw
 
 define <2 x i32> @test_sdiv_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
 ; CHECK-LABEL: @test_sdiv_canonicalize_vec(
-; CHECK-NEXT:    [[SDIV1:%.*]] = sdiv <2 x i32> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[SDIV:%.*]] = sub nsw <2 x i32> zeroinitializer, [[SDIV1]]
+; CHECK-NEXT:    [[NEG:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT:    [[SDIV:%.*]] = sdiv <2 x i32> [[NEG]], [[Y:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[SDIV]]
 ;
   %neg = sub nsw <2 x i32> <i32 0, i32 0>, %x
@@ -72,8 +71,9 @@ define i32 @test_sdiv_canonicalize_multi
   ret i32 %sdiv2
 }
 
-; There is combination: -(X/CE) -> (X/-CE).
-; If combines (X/-CE) to -(X/CE), make sure don't combine them endless.
+; There is combination: (X/-CE) -> -(X/CE)
+; There is another combination: -(X/CE) -> (X/-CE)
+; Make sure don't combine them endless.
 
 @X = global i32 5
 




More information about the llvm-commits mailing list