Skip to content

Commit ae1d93f

Browse files
committed
Fixups
1 parent be65788 commit ae1d93f

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,21 @@ bool DAGTypeLegalizer::run() {
435435
#endif
436436
PerformExpensiveChecks();
437437

438-
// If the root changed (e.g. it was a dead load) update the root.
439-
DAG.setRoot(Dummy.getValue());
438+
// Get the value of the original root after type legalization.
439+
SDValue Root = Dummy.getValue();
440+
441+
// Get the current root value, if it's not null combine it with the original
442+
// root to prevent it being removed as a dead node.
443+
if (SDValue LegalRoot = DAG.getRoot()) {
444+
Root = DAG.getNode(ISD::TokenFactor, SDLoc(LegalRoot), MVT::Other, Root,
445+
LegalRoot);
446+
// The token_factor should not need any legalization (as both inputs have
447+
// already been legalized).
448+
Root->setNodeId(Processed);
449+
}
450+
451+
// Restore the root.
452+
DAG.setRoot(Root);
440453

441454
// Remove dead nodes. This is important to do for cleanliness but also before
442455
// the checking loop below. Implicit folding by the DAG.getNode operators and

llvm/test/CodeGen/PowerPC/llvm.modf.ll

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,86 @@ define ppc_fp128 @test_modf_ppcf128_only_use_intergral(ppc_fp128 %a) {
350350
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 1
351351
ret ppc_fp128 %result.1
352352
}
353+
354+
define ppc_fp128 @test_modf_ppcf128_only_use_fractional(ppc_fp128 %a) {
355+
; CHECK-LABEL: test_modf_ppcf128_only_use_fractional:
356+
; CHECK: # %bb.0:
357+
; CHECK-NEXT: mflr r0
358+
; CHECK-NEXT: stdu r1, -48(r1)
359+
; CHECK-NEXT: std r0, 64(r1)
360+
; CHECK-NEXT: .cfi_def_cfa_offset 48
361+
; CHECK-NEXT: .cfi_offset lr, 16
362+
; CHECK-NEXT: addi r5, r1, 32
363+
; CHECK-NEXT: bl modfl
364+
; CHECK-NEXT: nop
365+
; CHECK-NEXT: addi r1, r1, 48
366+
; CHECK-NEXT: ld r0, 16(r1)
367+
; CHECK-NEXT: mtlr r0
368+
; CHECK-NEXT: blr
369+
%result = call { ppc_fp128, ppc_fp128 } @llvm.modf.ppcf128(ppc_fp128 %a)
370+
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 0
371+
ret ppc_fp128 %result.1
372+
}
373+
374+
define { ppc_fp128, ppc_fp128 } @test_modf_ppcf128_tail_call(ppc_fp128 %a) {
375+
; CHECK-LABEL: test_modf_ppcf128_tail_call:
376+
; CHECK: # %bb.0:
377+
; CHECK-NEXT: mflr r0
378+
; CHECK-NEXT: stdu r1, -48(r1)
379+
; CHECK-NEXT: std r0, 64(r1)
380+
; CHECK-NEXT: .cfi_def_cfa_offset 48
381+
; CHECK-NEXT: .cfi_offset lr, 16
382+
; CHECK-NEXT: addi r5, r1, 32
383+
; CHECK-NEXT: bl modfl
384+
; CHECK-NEXT: nop
385+
; CHECK-NEXT: lfd f3, 32(r1)
386+
; CHECK-NEXT: lfd f4, 40(r1)
387+
; CHECK-NEXT: addi r1, r1, 48
388+
; CHECK-NEXT: ld r0, 16(r1)
389+
; CHECK-NEXT: mtlr r0
390+
; CHECK-NEXT: blr
391+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.modf.ppcf128(ppc_fp128 %a)
392+
ret { ppc_fp128, ppc_fp128 } %result
393+
}
394+
395+
define ppc_fp128 @test_modf_ppcf128_only_use_intergral_tail_call(ppc_fp128 %a) {
396+
; CHECK-LABEL: test_modf_ppcf128_only_use_intergral_tail_call:
397+
; CHECK: # %bb.0:
398+
; CHECK-NEXT: mflr r0
399+
; CHECK-NEXT: stdu r1, -48(r1)
400+
; CHECK-NEXT: std r0, 64(r1)
401+
; CHECK-NEXT: .cfi_def_cfa_offset 48
402+
; CHECK-NEXT: .cfi_offset lr, 16
403+
; CHECK-NEXT: addi r5, r1, 32
404+
; CHECK-NEXT: bl modfl
405+
; CHECK-NEXT: nop
406+
; CHECK-NEXT: lfd f1, 32(r1)
407+
; CHECK-NEXT: lfd f2, 40(r1)
408+
; CHECK-NEXT: addi r1, r1, 48
409+
; CHECK-NEXT: ld r0, 16(r1)
410+
; CHECK-NEXT: mtlr r0
411+
; CHECK-NEXT: blr
412+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.modf.ppcf128(ppc_fp128 %a)
413+
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 1
414+
ret ppc_fp128 %result.1
415+
}
416+
417+
define ppc_fp128 @test_modf_ppcf128_only_use_fractional_tail_call(ppc_fp128 %a) {
418+
; CHECK-LABEL: test_modf_ppcf128_only_use_fractional_tail_call:
419+
; CHECK: # %bb.0:
420+
; CHECK-NEXT: mflr r0
421+
; CHECK-NEXT: stdu r1, -48(r1)
422+
; CHECK-NEXT: std r0, 64(r1)
423+
; CHECK-NEXT: .cfi_def_cfa_offset 48
424+
; CHECK-NEXT: .cfi_offset lr, 16
425+
; CHECK-NEXT: addi r5, r1, 32
426+
; CHECK-NEXT: bl modfl
427+
; CHECK-NEXT: nop
428+
; CHECK-NEXT: addi r1, r1, 48
429+
; CHECK-NEXT: ld r0, 16(r1)
430+
; CHECK-NEXT: mtlr r0
431+
; CHECK-NEXT: blr
432+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.modf.ppcf128(ppc_fp128 %a)
433+
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 0
434+
ret ppc_fp128 %result.1
435+
}

0 commit comments

Comments
 (0)