[llvm] r372007 - [InstCombine] remove unneeded one-use checks for icmp fold
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 09:15:25 PDT 2019
Author: spatel
Date: Mon Sep 16 09:15:25 2019
New Revision: 372007
URL: http://llvm.org/viewvc/llvm-project?rev=372007&view=rev
Log:
[InstCombine] remove unneeded one-use checks for icmp fold
Related folds were added in:
rL125734
...the code comment about register pressure is discussed in
more detail in:
https://bugs.llvm.org/show_bug.cgi?id=2698
But 10 years later, perf testing bzip2 with this change now
shows a slight (0.2% average) improvement on Haswell although
that's probably within test noise.
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 and rL371981 are related patches in this series.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp-add.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=372007&r1=372006&r2=372007&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon Sep 16 09:15:25 2019
@@ -3697,11 +3697,8 @@ Instruction *InstCombiner::foldICmpBinOp
C == Op0 ? D : C);
// icmp (A+B), (A+D) -> icmp B, D 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.
- BO0->hasOneUse() && BO1->hasOneUse()) {
+ NoOp1WrapProblem) {
// Determine Y and Z in the form icmp (X+Y), (X+Z).
Value *Y, *Z;
if (A == C) {
Modified: llvm/trunk/test/Transforms/InstCombine/icmp-add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp-add.ll?rev=372007&r1=372006&r2=372007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp-add.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp-add.ll Mon Sep 16 09:15:25 2019
@@ -483,7 +483,7 @@ define i1 @common_op_nsw_extra_uses(i32
; CHECK-NEXT: call void @use(i32 [[LHS]])
; CHECK-NEXT: [[RHS:%.*]] = add nsw i32 [[Y:%.*]], [[Z]]
; CHECK-NEXT: call void @use(i32 [[RHS]])
-; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nsw i32 %x, %z
@@ -512,7 +512,7 @@ define i1 @common_op_nuw_extra_uses(i32
; CHECK-NEXT: call void @use(i32 [[LHS]])
; CHECK-NEXT: [[RHS:%.*]] = add nuw i32 [[Z]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i32 [[RHS]])
-; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[LHS]], [[RHS]]
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nuw i32 %x, %z
@@ -609,8 +609,7 @@ define void @bzip1(i8 %a, i8 %b, i8 %x)
define void @bzip2(i8 %a, i8 %b, i8 %x) {
; CHECK-LABEL: @bzip2(
; CHECK-NEXT: [[ADD1:%.*]] = add i8 [[A:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[ADD2:%.*]] = add i8 [[B:%.*]], [[X]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ADD1]], [[ADD2]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], [[B:%.*]]
; CHECK-NEXT: call void @use1(i1 [[CMP]])
; CHECK-NEXT: call void @use8(i8 [[ADD1]])
; CHECK-NEXT: ret void
More information about the llvm-commits
mailing list