[llvm] r371940 - [InstCombine] remove unneeded one-use checks for icmp fold

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 13:56:34 PDT 2019


Author: spatel
Date: Sun Sep 15 13:56:34 2019
New Revision: 371940

URL: http://llvm.org/viewvc/llvm-project?rev=371940&view=rev
Log:
[InstCombine] remove unneeded one-use checks for icmp fold

This fold and several others were added in:
rL125734
...with no explanation for the one-use checks other than the code
comments about register pressure.

Given that this is IR canonicalization, we shouldn't be worried
about register pressure though; the backend should be able to
adjust for that as needed.

There are similar checks as noted with the TODO comments. I'm
hoping to remove those restrictions too, but if any of these
does cause a regression, it should be easier to correct by making
small, individual commits.

This is part of solving PR43310 the theoretically right way:
https://bugs.llvm.org/show_bug.cgi?id=43310
...ie, if we don't cripple basic transforms, then we won't
need to add special-case code to detect larger patterns.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=371940&r1=371939&r2=371940&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Sun Sep 15 13:56:34 2019
@@ -3695,6 +3695,7 @@ Instruction *InstCombiner::foldICmpBinOp
                         C == Op0 ? D : C);
 
   // icmp (X+Y), (X+Z) -> icmp Y, Z for equalities or if there is no overflow.
+  // TODO: The one-use checks should not be necessary.
   if (A && C && (A == C || A == D || B == C || B == D) && NoOp0WrapProblem &&
       NoOp1WrapProblem &&
       // Try not to increase register pressure.
@@ -3842,11 +3843,11 @@ Instruction *InstCombiner::foldICmpBinOp
     return new ICmpInst(Pred, C, D);
 
   // icmp (Y-X), (Z-X) -> icmp Y, Z for equalities or if there is no overflow.
-  if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem &&
-      // Try not to increase register pressure.
-      BO0->hasOneUse() && BO1->hasOneUse())
+  if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem)
     return new ICmpInst(Pred, A, C);
+
   // icmp (X-Y), (X-Z) -> icmp Z, Y for equalities or if there is no overflow.
+  // TODO: The one-use checks should not be necessary.
   if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem &&
       // Try not to increase register pressure.
       BO0->hasOneUse() && BO1->hasOneUse())

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=371940&r1=371939&r2=371940&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Sun Sep 15 13:56:34 2019
@@ -562,7 +562,7 @@ define i1 @test27_extra_uses(i32 %x, i32
 ; CHECK-NEXT:    call void @foo(i32 [[LHS]])
 ; CHECK-NEXT:    [[RHS:%.*]] = sub nsw i32 [[Y:%.*]], [[Z]]
 ; CHECK-NEXT:    call void @foo(i32 [[RHS]])
-; CHECK-NEXT:    [[C:%.*]] = icmp sgt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT:    [[C:%.*]] = icmp sgt i32 [[X]], [[Y]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %lhs = sub nsw i32 %x, %z
@@ -591,7 +591,7 @@ define i1 @test28_extra_uses(i32 %x, i32
 ; CHECK-NEXT:    call void @foo(i32 [[LHS]])
 ; CHECK-NEXT:    [[RHS:%.*]] = sub nuw i32 [[Y:%.*]], [[Z]]
 ; CHECK-NEXT:    call void @foo(i32 [[RHS]])
-; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[X]], [[Y]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %lhs = sub nuw i32 %x, %z




More information about the llvm-commits mailing list