[llvm] r362657 - [EarlyCSE] Add tests for negated min/max/abs [NFC]
Joseph Tremoulet via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 14:30:10 PDT 2019
Author: josepht
Date: Wed Jun 5 14:30:10 2019
New Revision: 362657
URL: http://llvm.org/viewvc/llvm-project?rev=362657&view=rev
Log:
[EarlyCSE] Add tests for negated min/max/abs [NFC]
Summary:
I'm planning to update the hashing logic to recognize their equivalence
in a subsequent change (D62644).
Reviewers: spatel
Reviewed By: spatel
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62918
Modified:
llvm/trunk/test/Transforms/EarlyCSE/commute.ll
Modified: llvm/trunk/test/Transforms/EarlyCSE/commute.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/EarlyCSE/commute.ll?rev=362657&r1=362656&r2=362657&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/commute.ll (original)
+++ llvm/trunk/test/Transforms/EarlyCSE/commute.ll Wed Jun 5 14:30:10 2019
@@ -107,6 +107,24 @@ define i1 @smin_swapped(i8 %a, i8 %b) {
ret i1 %r
}
+; Min/max can also have an inverted predicate and select operands.
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+
+define i1 @smin_inverted(i8 %a, i8 %b) {
+; CHECK-LABEL: @smin_inverted(
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
+; CHECK: ret i1
+;
+ %cmp1 = icmp slt i8 %a, %b
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %b
+ %m2 = select i1 %cmp2, i8 %b, i8 %a
+ %r = icmp eq i8 %m1, %m2
+ ret i1 %r
+}
+
define i8 @smax_commute(i8 %a, i8 %b) {
; CHECK-LABEL: @smax_commute(
; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A:%.*]], [[B:%.*]]
@@ -137,6 +155,22 @@ define i8 @smax_swapped(i8 %a, i8 %b) {
ret i8 %r
}
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+define i1 @smax_inverted(i8 %a, i8 %b) {
+; CHECK-LABEL: @smax_inverted(
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
+; CHECK: ret i1
+;
+ %cmp1 = icmp sgt i8 %a, %b
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %b
+ %m2 = select i1 %cmp2, i8 %b, i8 %a
+ %r = icmp eq i8 %m1, %m2
+ ret i1 %r
+}
+
define i8 @umin_commute(i8 %a, i8 %b) {
; CHECK-LABEL: @umin_commute(
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i8 [[A:%.*]], [[B:%.*]]
@@ -169,6 +203,22 @@ define <2 x i8> @umin_swapped(<2 x i8> %
ret <2 x i8> %r
}
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+define i1 @umin_inverted(i8 %a, i8 %b) {
+; CHECK-LABEL: @umin_inverted(
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
+; CHECK: ret i1
+;
+ %cmp1 = icmp ult i8 %a, %b
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %b
+ %m2 = select i1 %cmp2, i8 %b, i8 %a
+ %r = icmp eq i8 %m1, %m2
+ ret i1 %r
+}
+
define i8 @umax_commute(i8 %a, i8 %b) {
; CHECK-LABEL: @umax_commute(
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i8 [[A:%.*]], [[B:%.*]]
@@ -200,6 +250,22 @@ define i8 @umax_swapped(i8 %a, i8 %b) {
ret i8 %r
}
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+define i1 @umax_inverted(i8 %a, i8 %b) {
+; CHECK-LABEL: @umax_inverted(
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
+; CHECK: ret i1
+;
+ %cmp1 = icmp ugt i8 %a, %b
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %b
+ %m2 = select i1 %cmp2, i8 %b, i8 %a
+ %r = icmp eq i8 %m1, %m2
+ ret i1 %r
+}
+
; Min/max may exist with non-canonical operands. Value tracking can match those.
define i8 @smax_nsw(i8 %a, i8 %b) {
@@ -236,6 +302,24 @@ define i8 @abs_swapped(i8 %a) {
ret i8 %r
}
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+define i8 @abs_inverted(i8 %a) {
+; CHECK-LABEL: @abs_inverted(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], 0
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
+; CHECK: ret i8
+;
+ %neg = sub i8 0, %a
+ %cmp1 = icmp sgt i8 %a, 0
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %neg
+ %m2 = select i1 %cmp2, i8 %neg, i8 %a
+ %r = or i8 %m2, %m1
+ ret i8 %r
+}
+
define i8 @nabs_swapped(i8 %a) {
; CHECK-LABEL: @nabs_swapped(
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
@@ -250,6 +334,24 @@ define i8 @nabs_swapped(i8 %a) {
%m1 = select i1 %cmp1, i8 %a, i8 %neg
%m2 = select i1 %cmp2, i8 %neg, i8 %a
%r = xor i8 %m2, %m1
+ ret i8 %r
+}
+
+; TODO: Ensure we always recognize this (currently depends on hash collision)
+define i8 @nabs_inverted(i8 %a) {
+; CHECK-LABEL: @nabs_inverted(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0
+; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
+; CHECK: ret i8
+;
+ %neg = sub i8 0, %a
+ %cmp1 = icmp slt i8 %a, 0
+ %cmp2 = xor i1 %cmp1, -1
+ %m1 = select i1 %cmp1, i8 %a, i8 %neg
+ %m2 = select i1 %cmp2, i8 %neg, i8 %a
+ %r = xor i8 %m2, %m1
ret i8 %r
}
More information about the llvm-commits
mailing list