[llvm] [Mips] Fix compiler crash when returning fp128 after calling a functi… (PR #117525)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 26 04:42:00 PST 2024


================
@@ -2903,6 +2903,63 @@ entry:
   %cond = select i1 %cmp, fp128 %c, fp128 %d
   ret fp128 %cond
 }
+
+define { i8, i128 } @bar() {
+  ret { i8, i128 } zeroinitializer
+}
+
+define fp128 @call_retFP128() {
+; C_CC_FMT-LABEL: call_retFP128:
+; C_CC_FMT:       # %bb.0: # %entry
+; C_CC_FMT-NEXT:    daddiu $sp, $sp, -48
+; C_CC_FMT-NEXT:    .cfi_def_cfa_offset 48
+; C_CC_FMT-NEXT:    sd $ra, 40($sp) # 8-byte Folded Spill
+; C_CC_FMT-NEXT:    sd $gp, 32($sp) # 8-byte Folded Spill
+; C_CC_FMT-NEXT:    .cfi_offset 31, -8
+; C_CC_FMT-NEXT:    .cfi_offset 28, -16
+; C_CC_FMT-NEXT:    lui $1, %hi(%neg(%gp_rel(call_retFP128)))
+; C_CC_FMT-NEXT:    daddu $1, $1, $25
+; C_CC_FMT-NEXT:    daddiu $gp, $1, %lo(%neg(%gp_rel(call_retFP128)))
+; C_CC_FMT-NEXT:    daddiu $4, $sp, 0
+; C_CC_FMT-NEXT:    ld $25, %call16(bar)($gp)
+; C_CC_FMT-NEXT:    .reloc .Ltmp51, R_MIPS_JALR, bar
+; C_CC_FMT-NEXT:  .Ltmp51:
+; C_CC_FMT-NEXT:    jalr $25
+; C_CC_FMT-NEXT:    nop
+; C_CC_FMT-NEXT:    daddiu $2, $zero, 0
+; C_CC_FMT-NEXT:    daddiu $4, $zero, 0
+; C_CC_FMT-NEXT:    ld $gp, 32($sp) # 8-byte Folded Reload
+; C_CC_FMT-NEXT:    ld $ra, 40($sp) # 8-byte Folded Reload
+; C_CC_FMT-NEXT:    daddiu $sp, $sp, 48
+; C_CC_FMT-NEXT:    jr $ra
+; C_CC_FMT-NEXT:    nop
+;
+; CMP_CC_FMT-LABEL: call_retFP128:
+; CMP_CC_FMT:       # %bb.0: # %entry
+; CMP_CC_FMT-NEXT:    daddiu $sp, $sp, -48
+; CMP_CC_FMT-NEXT:    .cfi_def_cfa_offset 48
+; CMP_CC_FMT-NEXT:    sd $ra, 40($sp) # 8-byte Folded Spill
+; CMP_CC_FMT-NEXT:    sd $gp, 32($sp) # 8-byte Folded Spill
+; CMP_CC_FMT-NEXT:    .cfi_offset 31, -8
+; CMP_CC_FMT-NEXT:    .cfi_offset 28, -16
+; CMP_CC_FMT-NEXT:    lui $1, %hi(%neg(%gp_rel(call_retFP128)))
+; CMP_CC_FMT-NEXT:    daddu $1, $1, $25
+; CMP_CC_FMT-NEXT:    daddiu $gp, $1, %lo(%neg(%gp_rel(call_retFP128)))
+; CMP_CC_FMT-NEXT:    daddiu $4, $sp, 0
+; CMP_CC_FMT-NEXT:    ld $25, %call16(bar)($gp)
+; CMP_CC_FMT-NEXT:    .reloc .Ltmp51, R_MIPS_JALR, bar
+; CMP_CC_FMT-NEXT:  .Ltmp51:
+; CMP_CC_FMT-NEXT:    jalrc $25
+; CMP_CC_FMT-NEXT:    daddiu $2, $zero, 0
+; CMP_CC_FMT-NEXT:    daddiu $4, $zero, 0
+; CMP_CC_FMT-NEXT:    ld $gp, 32($sp) # 8-byte Folded Reload
+; CMP_CC_FMT-NEXT:    ld $ra, 40($sp) # 8-byte Folded Reload
+; CMP_CC_FMT-NEXT:    daddiu $sp, $sp, 48
+; CMP_CC_FMT-NEXT:    jrc $ra
+entry:
+  call { i8, i128 } @bar()
+  ret fp128 0xL00000000000000000000000000000000
+}
----------------
arsenm wrote:

Needs to test more situations (e.g. more aggregates with the fp128 in different positions), and this needs a comment. It's not obvious why there is the call to bar and it's not used for the return value.

Also test the caller side for fp128 returns, and tail calls 

https://github.com/llvm/llvm-project/pull/117525


More information about the llvm-commits mailing list