Skip to content

Commit d832138

Browse files
committed
Fixups
- Flag propagation - Legalize to individual sin/cos calls when FSINCOS unavailable - More tests
1 parent 36b08bd commit d832138

File tree

4 files changed

+449
-3
lines changed

4 files changed

+449
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,6 +3714,17 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
37143714
}
37153715
break;
37163716
}
3717+
case ISD::FSINCOS: {
3718+
if (isSinCosLibcallAvailable(Node, TLI))
3719+
break;
3720+
EVT VT = Node->getValueType(0);
3721+
SDValue Op = Node->getOperand(0);
3722+
SDNodeFlags Flags = Node->getFlags();
3723+
Tmp1 = DAG.getNode(ISD::FSIN, dl, VT, Op, Flags);
3724+
Tmp2 = DAG.getNode(ISD::FCOS, dl, VT, Op, Flags);
3725+
Results.append({Tmp1, Tmp2});
3726+
break;
3727+
}
37173728
case ISD::FMAD:
37183729
llvm_unreachable("Illegal fmad should never be formed");
37193730

@@ -5588,9 +5599,9 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
55885599
}
55895600
case ISD::FSINCOS: {
55905601
Tmp1 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(0));
5591-
Tmp2 = DAG.getNode(ISD::FSINCOS, dl, {NVT, NVT}, Tmp1);
5602+
Tmp2 = DAG.getNode(ISD::FSINCOS, dl, DAG.getVTList(NVT, NVT), Tmp1,
5603+
Node->getFlags());
55925604
Tmp3 = DAG.getIntPtrConstant(0, dl, /*isTarget=*/true);
5593-
55945605
for (unsigned ResNum = 0; ResNum < Node->getNumValues(); ResNum++)
55955606
Results.push_back(
55965607
DAG.getNode(ISD::FP_ROUND, dl, OVT, Tmp2.getValue(ResNum), Tmp3));

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6952,7 +6952,8 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
69526952
SmallVector<EVT, 2> ValueVTs;
69536953
ComputeValueVTs(TLI, DAG.getDataLayout(), I.getType(), ValueVTs);
69546954
SDVTList VTs = DAG.getVTList(ValueVTs);
6955-
setValue(&I, DAG.getNode(Opcode, sdl, VTs, getValue(I.getArgOperand(0))));
6955+
setValue(
6956+
&I, DAG.getNode(Opcode, sdl, VTs, getValue(I.getArgOperand(0)), Flags));
69566957
return;
69576958
}
69586959
case Intrinsic::arithmetic_fence: {

llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-sincos.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,17 @@ define { fp128, fp128 } @test_sincos_f128(fp128 %a) {
104104
%result = call { fp128, fp128 } @llvm.sincos.f16(fp128 %a)
105105
ret { fp128, fp128 } %result
106106
}
107+
108+
define { float, float } @test_sincos_f32_afn(float %a) {
109+
; CHECK-LABEL: name: test_sincos_f32_afn
110+
; CHECK: bb.1 (%ir-block.0):
111+
; CHECK-NEXT: liveins: $s0
112+
; CHECK-NEXT: {{ $}}
113+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
114+
; CHECK-NEXT: [[FSINCOS:%[0-9]+]]:_(s32), [[FSINCOS1:%[0-9]+]]:_ = afn G_FSINCOS [[COPY]]
115+
; CHECK-NEXT: $s0 = COPY [[FSINCOS]](s32)
116+
; CHECK-NEXT: $s1 = COPY [[FSINCOS1]](s32)
117+
; CHECK-NEXT: RET_ReallyLR implicit $s0, implicit $s1
118+
%result = call afn { float, float } @llvm.sincos.f32(float %a)
119+
ret { float, float } %result
120+
}

0 commit comments

Comments
 (0)