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

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 05:54:34 PDT 2019


Author: spatel
Date: Mon Sep 16 05:54:34 2019
New Revision: 371981

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

This fold and several others were added in:
rL125734 <https://reviews.llvm.org/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.

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.

rL371940 is a related patch in this series.

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=371981&r1=371980&r2=371981&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon Sep 16 05:54:34 2019
@@ -3849,10 +3849,7 @@ Instruction *InstCombiner::foldICmpBinOp
     return new ICmpInst(Pred, A, C);
 
   // icmp (A-B), (A-D) -> icmp D, B 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())
+  if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem)
     return new ICmpInst(Pred, D, B);
 
   // icmp (0-X) < cst --> x > -cst

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=371981&r1=371980&r2=371981&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Mon Sep 16 05:54:34 2019
@@ -734,7 +734,7 @@ define i1 @test37_extra_uses(i32 %x, i32
 ; CHECK-NEXT:    call void @foo(i32 [[LHS]])
 ; CHECK-NEXT:    [[RHS:%.*]] = sub nsw i32 [[X]], [[Z:%.*]]
 ; CHECK-NEXT:    call void @foo(i32 [[RHS]])
-; CHECK-NEXT:    [[C:%.*]] = icmp sgt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT:    [[C:%.*]] = icmp sgt i32 [[Z]], [[Y]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %lhs = sub nsw i32 %x, %y
@@ -763,7 +763,7 @@ define i1 @test38_extra_uses(i32 %x, i32
 ; CHECK-NEXT:    call void @foo(i32 [[LHS]])
 ; CHECK-NEXT:    [[RHS:%.*]] = sub nuw i32 [[X]], [[Z:%.*]]
 ; CHECK-NEXT:    call void @foo(i32 [[RHS]])
-; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[Z]], [[Y]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %lhs = sub nuw i32 %x, %y




More information about the llvm-commits mailing list