Skip to content

Commit 01b3e16

Browse files
committed
[X86] Use the same sequence for i128 ISD::ABS on 64-bit targets as we use for i64 on 32-bit targets.
Differential Revision: https://reviews.llvm.org/D87214
1 parent f3a6f6c commit 01b3e16

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
195195
setOperationAction(ISD::ABS , MVT::i32 , Custom);
196196
}
197197
setOperationAction(ISD::ABS , MVT::i64 , Custom);
198+
if (Subtarget.is64Bit())
199+
setOperationAction(ISD::ABS , MVT::i128 , Custom);
198200

199201
// Funnel shifts.
200202
for (auto ShiftOp : {ISD::FSHL, ISD::FSHR}) {
@@ -29719,9 +29721,12 @@ void X86TargetLowering::ReplaceNodeResults(SDNode *N,
2971929721
return;
2972029722
}
2972129723
case ISD::ABS: {
29722-
assert(N->getValueType(0) == MVT::i64 &&
29724+
assert((Subtarget.is64Bit() || N->getValueType(0) == MVT::i64) &&
2972329725
"Unexpected type (!= i64) on ABS.");
29724-
MVT HalfT = MVT::i32;
29726+
assert((!Subtarget.is64Bit() || N->getValueType(0) == MVT::i128) &&
29727+
"Unexpected type (!= i128) on ABS.");
29728+
MVT VT = N->getSimpleValueType(0);
29729+
MVT HalfT = VT == MVT::i128 ? MVT::i64 : MVT::i32;
2972529730
SDValue Lo, Hi, Tmp;
2972629731
SDVTList VTList = DAG.getVTList(HalfT, MVT::i1);
2972729732

@@ -29737,7 +29742,7 @@ void X86TargetLowering::ReplaceNodeResults(SDNode *N,
2973729742
SDValue(Lo.getNode(), 1));
2973829743
Hi = DAG.getNode(ISD::XOR, dl, HalfT, Tmp, Hi);
2973929744
Lo = DAG.getNode(ISD::XOR, dl, HalfT, Tmp, Lo);
29740-
Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi));
29745+
Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi));
2974129746
return;
2974229747
}
2974329748
// We might have generated v2f32 FMIN/FMAX operations. Widen them to v4f32.

llvm/test/CodeGen/X86/abs.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ define i64 @test_i64(i64 %a) nounwind {
132132
define i128 @test_i128(i128 %a) nounwind {
133133
; X64-LABEL: test_i128:
134134
; X64: # %bb.0:
135-
; X64-NEXT: xorl %edx, %edx
135+
; X64-NEXT: movq %rsi, %rdx
136136
; X64-NEXT: movq %rdi, %rax
137-
; X64-NEXT: negq %rax
138-
; X64-NEXT: sbbq %rsi, %rdx
139-
; X64-NEXT: testq %rsi, %rsi
140-
; X64-NEXT: cmovnsq %rdi, %rax
141-
; X64-NEXT: cmovnsq %rsi, %rdx
137+
; X64-NEXT: movq %rsi, %rcx
138+
; X64-NEXT: sarq $63, %rcx
139+
; X64-NEXT: addq %rcx, %rax
140+
; X64-NEXT: adcq %rcx, %rdx
141+
; X64-NEXT: xorq %rcx, %rax
142+
; X64-NEXT: xorq %rcx, %rdx
142143
; X64-NEXT: retq
143144
;
144145
; X86-LABEL: test_i128:

llvm/test/CodeGen/X86/iabs.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ define i128 @test_i128(i128 %a) nounwind {
191191
;
192192
; X64-LABEL: test_i128:
193193
; X64: # %bb.0:
194-
; X64-NEXT: xorl %edx, %edx
194+
; X64-NEXT: movq %rsi, %rdx
195195
; X64-NEXT: movq %rdi, %rax
196-
; X64-NEXT: negq %rax
197-
; X64-NEXT: sbbq %rsi, %rdx
198-
; X64-NEXT: testq %rsi, %rsi
199-
; X64-NEXT: cmovnsq %rdi, %rax
200-
; X64-NEXT: cmovnsq %rsi, %rdx
196+
; X64-NEXT: movq %rsi, %rcx
197+
; X64-NEXT: sarq $63, %rcx
198+
; X64-NEXT: addq %rcx, %rax
199+
; X64-NEXT: adcq %rcx, %rdx
200+
; X64-NEXT: xorq %rcx, %rax
201+
; X64-NEXT: xorq %rcx, %rdx
201202
; X64-NEXT: retq
202203
%tmp1neg = sub i128 0, %a
203204
%b = icmp sgt i128 %a, -1

0 commit comments

Comments
 (0)