Skip to content

Commit 6f3cb1d

Browse files
author
himadhith
committed
addressing review comments
1 parent d74869b commit 6f3cb1d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19208,9 +19208,17 @@ static SDValue combineADDToMAT_PCREL_ADDR(SDNode *N, SelectionDAG &DAG,
1920819208
return MatPCRel;
1920919209
}
1921019210

19211+
// Transform (add X, (build_vector (T 1), (T 1), ...)) -> (sub X, (XXLEQVOnes))
19212+
// XXLEQVOnes creates an all-1s vector (0xFFFFFFFF...) efficiently via xxleqv
19213+
// Mathematical identity: X + 1 = X - (-1)
19214+
// Applies to v4i32, v2i64, v8i16, v16i8 where all elements are constant 1
19215+
// Requirement: VSX feature for efficient xxleqv generation
1921119216
static SDValue combineADDToSUB(SDNode *N, SelectionDAG &DAG,
1921219217
const PPCSubtarget &Subtarget) {
19218+
1921319219
EVT VT = N->getValueType(0);
19220+
if (!Subtarget.hasVSX())
19221+
return SDValue();
1921419222

1921519223
// Handle v2i64, v4i32, v8i16 and v16i8 types
1921619224
if (!(VT == MVT::v8i16 || VT == MVT::v16i8 || VT == MVT::v4i32 ||
@@ -19221,10 +19229,6 @@ static SDValue combineADDToSUB(SDNode *N, SelectionDAG &DAG,
1922119229
SDValue RHS = N->getOperand(1);
1922219230

1922319231
// Check if RHS is BUILD_VECTOR
19224-
// To satisfy commutative property a+b = b+a
19225-
if (RHS.getOpcode() != ISD::BUILD_VECTOR)
19226-
std::swap(LHS, RHS);
19227-
1922819232
if (RHS.getOpcode() != ISD::BUILD_VECTOR)
1922919233
return SDValue();
1923019234

@@ -19243,7 +19247,7 @@ static SDValue combineADDToSUB(SDNode *N, SelectionDAG &DAG,
1924319247

1924419248
// Bitcast to the target vector type
1924519249
SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT, AllOnesVec);
19246-
19250+
1924719251
return DAG.getNode(ISD::SUB, DL, VT, LHS, Bitcast);
1924819252
}
1924919253

llvm/test/CodeGen/PowerPC/vec_add_sub_doubleword.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define <2 x i64> @increment_by_one(<2 x i64> %x) nounwind {
2525
; NOVSX-NEXT: addis 3, 2, .LCPI1_0@toc@ha
2626
; NOVSX-NEXT: addi 3, 3, .LCPI1_0@toc@l
2727
; NOVSX-NEXT: lvx 3, 0, 3
28-
; NOVSX-NEXT: vsubudm 2, 2, 3
28+
; NOVSX-NEXT: vaddudm 2, 2, 3
2929
; NOVSX-NEXT: blr
3030
%result = add <2 x i64> %x, <i64 1, i64 1>
3131
ret <2 x i64> %result

0 commit comments

Comments
 (0)