Skip to content

Commit ebe9944

Browse files
committed
[ISel] Legalized arithmetic.fence.f128 for 32-bits target
Reviewed By: Craig Topper, Wang Pengfei Differential Revision: https://reviews.llvm.org/D110467
1 parent 90fb73a commit ebe9944

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
6161
#endif
6262
llvm_unreachable("Do not know how to soften the result of this operator!");
6363

64+
case ISD::ARITH_FENCE: R = SoftenFloatRes_ARITH_FENCE(N); break;
6465
case ISD::MERGE_VALUES:R = SoftenFloatRes_MERGE_VALUES(N, ResNo); break;
6566
case ISD::BITCAST: R = SoftenFloatRes_BITCAST(N); break;
6667
case ISD::BUILD_PAIR: R = SoftenFloatRes_BUILD_PAIR(N); break;
@@ -206,6 +207,13 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FREEZE(SDNode *N) {
206207
GetSoftenedFloat(N->getOperand(0)));
207208
}
208209

210+
SDValue DAGTypeLegalizer::SoftenFloatRes_ARITH_FENCE(SDNode *N) {
211+
EVT Ty = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
212+
SDValue NewFence = DAG.getNode(ISD::ARITH_FENCE, SDLoc(N), Ty,
213+
GetSoftenedFloat(N->getOperand(0)));
214+
return NewFence;
215+
}
216+
209217
SDValue DAGTypeLegalizer::SoftenFloatRes_MERGE_VALUES(SDNode *N,
210218
unsigned ResNo) {
211219
SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,7 @@ void DAGTypeLegalizer::ExpandIntegerResult(SDNode *N, unsigned ResNo) {
22182218
report_fatal_error("Do not know how to expand the result of this "
22192219
"operator!");
22202220

2221+
case ISD::ARITH_FENCE: SplitRes_ARITH_FENCE(N, Lo, Hi); break;
22212222
case ISD::MERGE_VALUES: SplitRes_MERGE_VALUES(N, ResNo, Lo, Hi); break;
22222223
case ISD::SELECT: SplitRes_SELECT(N, Lo, Hi); break;
22232224
case ISD::SELECT_CC: SplitRes_SELECT_CC(N, Lo, Hi); break;

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
526526
SDValue SoftenFloatRes_Unary(SDNode *N, RTLIB::Libcall LC);
527527
SDValue SoftenFloatRes_Binary(SDNode *N, RTLIB::Libcall LC);
528528
SDValue SoftenFloatRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
529+
SDValue SoftenFloatRes_ARITH_FENCE(SDNode *N);
529530
SDValue SoftenFloatRes_BITCAST(SDNode *N);
530531
SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
531532
SDValue SoftenFloatRes_ConstantFP(SDNode *N);
@@ -1019,6 +1020,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
10191020
// Generic Result Splitting.
10201021
void SplitRes_MERGE_VALUES(SDNode *N, unsigned ResNo,
10211022
SDValue &Lo, SDValue &Hi);
1023+
void SplitRes_ARITH_FENCE (SDNode *N, SDValue &Lo, SDValue &Hi);
10221024
void SplitRes_SELECT (SDNode *N, SDValue &Lo, SDValue &Hi);
10231025
void SplitRes_SELECT_CC (SDNode *N, SDValue &Lo, SDValue &Hi);
10241026
void SplitRes_UNDEF (SDNode *N, SDValue &Lo, SDValue &Hi);

llvm/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,13 @@ void DAGTypeLegalizer::SplitRes_FREEZE(SDNode *N, SDValue &Lo, SDValue &Hi) {
571571
Lo = DAG.getNode(ISD::FREEZE, dl, L.getValueType(), L);
572572
Hi = DAG.getNode(ISD::FREEZE, dl, H.getValueType(), H);
573573
}
574+
575+
void DAGTypeLegalizer::SplitRes_ARITH_FENCE(SDNode *N, SDValue &Lo,
576+
SDValue &Hi) {
577+
SDValue L, H;
578+
SDLoc DL(N);
579+
GetSplitOp(N->getOperand(0), L, H);
580+
581+
Lo = DAG.getNode(ISD::ARITH_FENCE, DL, L.getValueType(), L);
582+
Hi = DAG.getNode(ISD::ARITH_FENCE, DL, H.getValueType(), H);
583+
}

llvm/test/CodeGen/X86/arithmetic_fence.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,58 @@ define <2 x float> @f6(<2 x float> %a) {
156156
ret <2 x float> %3
157157
}
158158

159+
; This @f7 IR test can be generated from flowing c test:
160+
;
161+
; typedef __float128 TYPE;
162+
; TYPE foo(TYPE *qr) {
163+
; TYPE re =__arithmetic_fence(*qr);
164+
; return re;
165+
;}
166+
;
167+
; with flowing build command:
168+
; clang -cc1 -triple i386-pc-linux-gnu -mreassociate t.c -emit-llvm -O2
169+
170+
define dso_local fp128 @foo(fp128* nocapture readonly %qr) local_unnamed_addr{
171+
; X86-LABEL: foo:
172+
; X86: # %bb.0: # %entry
173+
; X86-NEXT: pushl %edi
174+
; X86-NEXT: .cfi_def_cfa_offset 8
175+
; X86-NEXT: pushl %esi
176+
; X86-NEXT: .cfi_def_cfa_offset 12
177+
; X86-NEXT: .cfi_offset %esi, -12
178+
; X86-NEXT: .cfi_offset %edi, -8
179+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
180+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
181+
; X86-NEXT: movl 12(%ecx), %edx
182+
; X86-NEXT: movl 8(%ecx), %esi
183+
; X86-NEXT: movl (%ecx), %edi
184+
; X86-NEXT: movl 4(%ecx), %ecx
185+
; X86-NEXT: #ARITH_FENCE
186+
; X86-NEXT: #ARITH_FENCE
187+
; X86-NEXT: #ARITH_FENCE
188+
; X86-NEXT: #ARITH_FENCE
189+
; X86-NEXT: movl %edx, 12(%eax)
190+
; X86-NEXT: movl %esi, 8(%eax)
191+
; X86-NEXT: movl %ecx, 4(%eax)
192+
; X86-NEXT: movl %edi, (%eax)
193+
; X86-NEXT: popl %esi
194+
; X86-NEXT: .cfi_def_cfa_offset 8
195+
; X86-NEXT: popl %edi
196+
; X86-NEXT: .cfi_def_cfa_offset 4
197+
; X86-NEXT: retl $4
198+
;
199+
; X64-LABEL: foo:
200+
; X64: # %bb.0: # %entry
201+
; X64-NEXT: vmovaps (%rdi), %xmm0
202+
; X64-NEXT: #ARITH_FENCE
203+
; X64-NEXT: retq
204+
entry:
205+
%0 = load fp128, fp128* %qr, align 16
206+
%1 = tail call reassoc fp128 @llvm.arithmetic.fence.f128(fp128 %0)
207+
ret fp128 %1
208+
}
209+
210+
declare fp128 @llvm.arithmetic.fence.f128(fp128)
159211
declare float @llvm.arithmetic.fence.f32(float)
160212
declare double @llvm.arithmetic.fence.f64(double)
161213
declare <2 x float> @llvm.arithmetic.fence.v2f32(<2 x float>)

0 commit comments

Comments
 (0)