This is an archive of the discontinued LLVM Phabricator instance.

[GISel]: Add helpers for easy building G_FCONSTANT along with matchers
ClosedPublic

Authored by aditya_nandakumar on Mar 5 2018, 5:53 PM.

Details

Summary

Added helpers to build G_FCONSTANT, along with matching ConstantFP and unit tests for the same.

Sample usage.

auto MIB = Builder.buildFConstant(DstReg, 0.5, s32); // Build IEEESingle

For Matching the above

const ConstantFP* Tmp;
mi_match(DstReg, MRI, m_GFCst(Tmp));

Diff Detail

Event Timeline

Perhaps we could add some checks to make sure that the user is not building a larger floating point constant into a register of smaller type under Asserts. Not sure if that's ever a valid use case - but if it's not I'll definitely add that bit.

Added check to assert that the sizes are compatible. Also moved comments for the two functions from Utils.cpp to Utils.h.

volkan added inline comments.Mar 8 2018, 12:05 PM
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
291

Could you check this in MachineVerifier as well?

295

We already know DstTy here, can't we just use DstTy instead of Ty?

lib/CodeGen/GlobalISel/Utils.cpp
217

We don't need fltSemantics for float and double so I think we can move this to getAPFloatFromSize and always use getAPFloatFromSize to create an APFloat. What do you think?

240

This can be simplified as APFloat APF(Val); if you prefer.

unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
292

This can be replaced with getAPFloatFromSize(0.5, 16).

aditya_nandakumar marked 2 inline comments as done.Mar 8 2018, 12:32 PM
aditya_nandakumar added inline comments.
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
291

I can do this in a separate commit as this is only adding builder helpers vs adding verifier + fixing tests.

295

I was hoping to avoid needless getGenericVirtualReg() -> getType() lookups.
I've gone ahead and removed it for now.

unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
292

I was hoping to test that part as well here (getting the correct APFloat).

Updated based on Volkan's feedback.

volkan accepted this revision.Mar 8 2018, 2:45 PM

LGTM. Thank you Aditya.

include/llvm/CodeGen/GlobalISel/Utils.h
38

I think fltSemantics and LLT are no longer required. Could you remove them before committing?

lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
291

That works for me.

This revision is now accepted and ready to land.Mar 8 2018, 2:45 PM

Committed in r327152