Skip to content

Commit b8b253b

Browse files
committed
Address review comments
And run this combiner rule in both pre- and post-legalized phase.
1 parent 3e85bc4 commit b8b253b

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ inline bool isBitwiseLogicOp(unsigned Opcode) {
15061506
return Opcode == ISD::AND || Opcode == ISD::OR || Opcode == ISD::XOR;
15071507
}
15081508

1509+
/// Given a \p MinMaxOpc of ISD::(U|S)MIN or ISD::(U|S)MAX, returns
1510+
/// ISD::(U|S)MAX and ISD::(U|S)MIN, respectively.
15091511
NodeType getInverseMinMaxOpcode(unsigned MinMaxOpc);
15101512

15111513
/// Get underlying scalar opcode for VECREDUCE opcode.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,8 +3957,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39573957
SDValue X;
39583958
SDValue S0;
39593959
auto NegPat = m_AllOf(m_Neg(m_Deferred(X)), m_Value(S0));
3960-
if (LegalOperations &&
3961-
sd_match(N1, m_OneUse(m_AnyOf(m_SMax(m_Value(X), NegPat),
3960+
if (sd_match(N1, m_OneUse(m_AnyOf(m_SMax(m_Value(X), NegPat),
39623961
m_UMax(m_Value(X), NegPat),
39633962
m_SMin(m_Value(X), NegPat),
39643963
m_UMin(m_Value(X), NegPat))))) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s
3+
4+
define <2 x i64> @expanded_fixed_neg_abs64(<2 x i64> %x) {
5+
; CHECK-LABEL: expanded_fixed_neg_abs64:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
8+
; CHECK-NEXT: vrsub.vi v9, v8, 0
9+
; CHECK-NEXT: vmin.vv v8, v8, v9
10+
; CHECK-NEXT: ret
11+
%t = sub <2 x i64> <i64 0, i64 0>, %x
12+
%t1 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %t, <2 x i64> %x)
13+
%t2 = sub <2 x i64> <i64 0, i64 0>, %t1
14+
ret <2 x i64> %t2
15+
}
16+
17+
define <2 x i64> @expanded_fixed_neg_abs64_unsigned(<2 x i64> %x) {
18+
; CHECK-LABEL: expanded_fixed_neg_abs64_unsigned:
19+
; CHECK: # %bb.0:
20+
; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
21+
; CHECK-NEXT: vrsub.vi v9, v8, 0
22+
; CHECK-NEXT: vminu.vv v8, v8, v9
23+
; CHECK-NEXT: ret
24+
%t = sub <2 x i64> <i64 0, i64 0>, %x
25+
%t1 = call <2 x i64> @llvm.umax.v2i64(<2 x i64> %t, <2 x i64> %x)
26+
%t2 = sub <2 x i64> <i64 0, i64 0>, %t1
27+
ret <2 x i64> %t2
28+
}
29+
30+
define <2 x i64> @expanded_fixed_neg_inv_abs64(<2 x i64> %x) {
31+
; CHECK-LABEL: expanded_fixed_neg_inv_abs64:
32+
; CHECK: # %bb.0:
33+
; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
34+
; CHECK-NEXT: vrsub.vi v9, v8, 0
35+
; CHECK-NEXT: vmax.vv v8, v8, v9
36+
; CHECK-NEXT: ret
37+
%t = sub <2 x i64> <i64 0, i64 0>, %x
38+
%t1 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %t, <2 x i64> %x)
39+
%t2 = sub <2 x i64> <i64 0, i64 0>, %t1
40+
ret <2 x i64> %t2
41+
}
42+
43+
define <2 x i64> @expanded_fixed_neg_inv_abs64_unsigned(<2 x i64> %x) {
44+
; CHECK-LABEL: expanded_fixed_neg_inv_abs64_unsigned:
45+
; CHECK: # %bb.0:
46+
; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
47+
; CHECK-NEXT: vrsub.vi v9, v8, 0
48+
; CHECK-NEXT: vmaxu.vv v8, v8, v9
49+
; CHECK-NEXT: ret
50+
%t = sub <2 x i64> <i64 0, i64 0>, %x
51+
%t1 = call <2 x i64> @llvm.umin.v2i64(<2 x i64> %t, <2 x i64> %x)
52+
%t2 = sub <2 x i64> <i64 0, i64 0>, %t1
53+
ret <2 x i64> %t2
54+
}

0 commit comments

Comments
 (0)