[llvm] r321936 - [InstCombine] relax use constraint for min/max (~a, ~b) --> ~min/max(a, b)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 6 09:34:22 PST 2018
Author: spatel
Date: Sat Jan 6 09:34:22 2018
New Revision: 321936
URL: http://llvm.org/viewvc/llvm-project?rev=321936&view=rev
Log:
[InstCombine] relax use constraint for min/max (~a, ~b) --> ~min/max(a, b)
In the minimal case, this won't remove instructions, but it still improves
uses of existing values.
In the motivating example from PR35834, it does remove instructions, and
sets that case up to be optimized by something like D41603:
https://reviews.llvm.org/D41603
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=321936&r1=321935&r2=321936&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Sat Jan 6 09:34:22 2018
@@ -1555,8 +1555,8 @@ Instruction *InstCombiner::visitSelectIn
// MAX(~a, ~b) -> ~MIN(a, b)
// MIN(~a, ~b) -> ~MAX(a, b)
Value *A, *B;
- if (match(LHS, m_Not(m_Value(A))) && LHS->getNumUses() <= 2 &&
- match(RHS, m_Not(m_Value(B))) && RHS->getNumUses() <= 2) {
+ if (match(LHS, m_Not(m_Value(A))) && match(RHS, m_Not(m_Value(B))) &&
+ (LHS->getNumUses() <= 2 || RHS->getNumUses() <= 2)) {
CmpInst::Predicate InvertedPred =
getCmpPredicateForMinMax(getInverseMinMaxSelectPattern(SPF));
Value *InvertedCmp = Builder.CreateICmp(InvertedPred, A, B);
Modified: llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll?rev=321936&r1=321935&r2=321936&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll Sat Jan 6 09:34:22 2018
@@ -47,9 +47,9 @@ declare void @extra_use(i8)
define i8 @umin_not_1_extra_use(i8 %x, i8 %y) {
; CHECK-LABEL: @umin_not_1_extra_use(
; CHECK-NEXT: [[NX:%.*]] = xor i8 %x, -1
-; CHECK-NEXT: [[NY:%.*]] = xor i8 %y, -1
-; CHECK-NEXT: [[CMPXY:%.*]] = icmp ult i8 [[NX]], [[NY]]
-; CHECK-NEXT: [[MINXY:%.*]] = select i1 [[CMPXY]], i8 [[NX]], i8 [[NY]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 %x, %y
+; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 %x, i8 %y
+; CHECK-NEXT: [[MINXY:%.*]] = xor i8 [[TMP2]], -1
; CHECK-NEXT: call void @extra_use(i8 [[NX]])
; CHECK-NEXT: ret i8 [[MINXY]]
;
@@ -84,15 +84,13 @@ define i8 @umin_not_2_extra_use(i8 %x, i
define i8 @umin3_not(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: @umin3_not(
-; CHECK-NEXT: [[NX:%.*]] = xor i8 %x, -1
-; CHECK-NEXT: [[NY:%.*]] = xor i8 %y, -1
-; CHECK-NEXT: [[NZ:%.*]] = xor i8 %z, -1
; CHECK-NEXT: [[CMPYX:%.*]] = icmp ult i8 %y, %x
-; CHECK-NEXT: [[CMPXZ:%.*]] = icmp ult i8 [[NX]], [[NZ]]
-; CHECK-NEXT: [[MINXZ:%.*]] = select i1 [[CMPXZ]], i8 [[NX]], i8 [[NZ]]
-; CHECK-NEXT: [[CMPYZ:%.*]] = icmp ult i8 [[NY]], [[NZ]]
-; CHECK-NEXT: [[MINYZ:%.*]] = select i1 [[CMPYZ]], i8 [[NY]], i8 [[NZ]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPYX]], i8 [[MINXZ]], i8 [[MINYZ]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 %x, %z
+; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 %x, i8 %z
+; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i8 %y, %z
+; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i8 %y, i8 %z
+; CHECK-NEXT: [[R_V:%.*]] = select i1 [[CMPYX]], i8 [[TMP2]], i8 [[TMP4]]
+; CHECK-NEXT: [[R:%.*]] = xor i8 [[R:%.*]].v, -1
; CHECK-NEXT: ret i8 [[R]]
;
%nx = xor i8 %x, -1
More information about the llvm-commits
mailing list