This is an archive of the discontinued LLVM Phabricator instance.

Fix sign extension for MIPS64 in makeLibCall function
ClosedPublic

Authored by spetrovic on Feb 20 2015, 8:18 AM.

Details

Summary

Fixing sign extension in makeLibCall for MIPS64. In MIPS64 architecture all 32 bit arguments (int, unsigned int, float 32 (soft float)) must be sign extended. This fixes test "MultiSource/Applications/oggenc/"

Diff Detail

Repository
rL LLVM

Event Timeline

spetrovic updated this revision to Diff 20406.Feb 20 2015, 8:18 AM
spetrovic retitled this revision from to Fix makeLibCall arguments for SoftenFloatRes_FRINT function.
spetrovic updated this object.
spetrovic edited the test plan for this revision. (Show Details)
spetrovic added reviewers: t.p.northover, petarj.
spetrovic set the repository for this revision to rL LLVM.
spetrovic added a subscriber: Unknown Object (MLST).

This is target-independent code, what does, "This should not affect other architectures." mean? Maybe you need a new target callback? Why does this affect only FRINT and not also FCEIL, FTRUNC, FNEARBYINT, FROUND, FFLOOR?

test/CodeGen/Mips/mips64rintfsf.ll
21 ↗(On Diff #20406)

Please remove any unnecessary attributes.

spetrovic updated this revision to Diff 21578.Mar 10 2015, 7:54 AM
spetrovic updated this object.

I think you are right about target callback, did you have something like this in mind ? I currently found the problem in this function. The problem exist in other functions, but I haven't seen it manifest yet. I will do some extra tests on those functions next. I have seen GCC and LLVM (for other cases) do sign extension on float arguments.

spetrovic edited reviewers, added: hfinkel; removed: t.p.northover.Mar 10 2015, 7:55 AM
spetrovic updated this revision to Diff 21584.Mar 10 2015, 8:21 AM

Fixed white spaces.

petarj added inline comments.Mar 10 2015, 8:27 AM
include/llvm/Target/TargetLowering.h
1074 ↗(On Diff #21578)

Can you please add a comment before the function?

lib/Target/Mips/MipsISelLowering.cpp
3034 ↗(On Diff #21578)

Nit: remove empty line.

3035 ↗(On Diff #21578)

I believe you should be checking for Subtarget.abiUsesSoftFloat() too.
Upper 32bits are undefined for hard float ABI.

3036 ↗(On Diff #21578)

Remove empty line.

lib/Target/Mips/MipsISelLowering.h
477 ↗(On Diff #21578)

Add an empty line above this.

spetrovic updated this revision to Diff 21588.Mar 10 2015, 8:58 AM

Comments addressed.

spetrovic updated this revision to Diff 21591.Mar 10 2015, 9:23 AM

Test updated because of changes on LLVM.

hfinkel edited edge metadata.Mar 10 2015, 2:04 PM

Regarding the other functions, is there a reason why the obvious modification to the regression test for this one won't work?

Generically, I'd like to see as much testing coverage as possible; when you make the change, I think that it should be done for all of the functions in a consistent manner. Please test as much as you can, but if there are some you can't on your target, that's okay.

lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
494 ↗(On Diff #21591)

Why did you name the callback shouldSignExtendFloat32InAbiCall when the use is not specific to f32? I recommend having the callback take the type, and taking Float32 out of the name.

petarj added inline comments.Mar 10 2015, 6:06 PM
lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
494 ↗(On Diff #21591)

The need for this change comes from MIPS64 decision to keep 32-bit values in registers by sign-extending them to 64 bits.
Maybe the function name should reflect that?

hfinkel added inline comments.Mar 10 2015, 10:57 PM
lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
494 ↗(On Diff #21591)

No, this is target-independent code.

spetrovic updated this revision to Diff 22252.Mar 19 2015, 5:57 AM
spetrovic retitled this revision from Fix makeLibCall arguments for SoftenFloatRes_FRINT function to Fix sign extension for MIPS64 in makeLibCall function.
spetrovic updated this object.
spetrovic edited edge metadata.

makeLibCall function is patched, now every function argument and return value are sign extended if needed. In MIPS64 architecture all 32 bit arguments (int, unsigned int, float 32) must be sign extended. In makeLibCall function 32 bit arguments are converted to int32, so there is check if is any MIPS64 architecture, soft float ABI, and int 32 type then do sign extension. This patch is only for MIPS64 and doesn't affect other architectures.

hfinkel added inline comments.Mar 20 2015, 10:21 AM
include/llvm/Target/TargetLowering.h
1075 ↗(On Diff #22252)

This is certainly better, my only issue now is with the function name. The term 'ABI call' seems ambiguous (and appears in the Mips backend, but nowhere else in the same way), and this specifically applies to calls generated with makeLibCall. How about naming it?

shouldSignExtendTypeInLibCall

which seems to fit better with general LLVM terminology.

spetrovic updated this revision to Diff 22359.Mar 20 2015, 10:53 AM

Function name changed to shouldSignExtendTypeInLibCall.

hfinkel accepted this revision.Mar 20 2015, 10:56 AM
hfinkel edited edge metadata.

LGTM, thanks!

This revision is now accepted and ready to land.Mar 20 2015, 10:56 AM
This revision was automatically updated to reflect the committed changes.