TLI.getSetCCResultType() and/or MVT broken by design?

I’m running into lots of problems with this call back. Mostly the problem occurs because this callback is used before types are legalized. However, the code generator does not have a 1-1 correspondence between all LLVM types and the codegen types. This leads to problems when getSetCCResultType is passed in an invalid type, but has a valid LLVM type attached to it. An example is <3 x float>. getSetCCResultType can return any type, and in the AMDIL backends case, for a <3 x float>, returns the corresponding integer version of the vector. The problem comes in code like the following(comments removed):

This is from DAGCombiner.cpp:visitSIGN_EXTEND.

EVT N0VT = N0.getOperand(0).getValueType();

EVT SVT = TLI.getSetCCResultType(N0VT);

if (VT.getSizeInBits() == SVT.getSizeInBits())

return DAG.getSetCC(N->getDebugLoc(), VT, N0.getOperand(0),

N0.getOperand(1),

cast(N0.getOperand(2))->get());

SVT.getSizeInBits() crashes, because TLI.getSetCCResultType returns an invalid MVT type and LLVMTy is NULL. Since there is no way to specify the LLVMTy manually, there is no way to fix this without finding all of the locations that use this and disabling them.

I’m disabling via VT.isPow2VectorType() because an extra check, but it seems like this isn’t preferable. So should I conditionalize the pre-liegalized check, or allow a backend to set the LLVMTy of newly created MVT types.

So, is the design to disallow backends to set this broken, or what is expected? Let me know what you think is the best way forward.

Thanks,

Micah

Hi Micah,

I think that getSetCCResultType should only be called for legal types. Disabling it on isPow2VectorType is not the way to go because there are other illegal vector types which are pow-of-two. I suggest that you call it only after type-legalization.

BTW, you can’t set the LLVMTy yourself because you don’t have access to the LLVMContext at that point.

Nadav

if (N0.getOpcode() == ISD::SETCC

&& (LegalOperations

(!LegalOperations && VT.isPow2VectorType())))

But the comment right after it is:

// sext(setcc) → sext_in_reg(vsetcc) for vectors.

// Only do this before legalize for now.

if (VT.isVector() && !LegalOperations) {

So, these optimizations are never safe in the general case if we can’t guarantee that TLI.getSetCCResultType() returns a valid type.

We no longer have vsetcc, so the comment is wrong. The code looks incorrect. The fact that a vector is power-of-two does not guarantee anything about its legality. For example <128 x i64> would pass the condition in the code below, and die on most targets.

Yep. So I’m guessing getSetCCResultType should never be called with an invalid type. This might not be the only spot that this happens, just the one that I happen to be tripping up on.

Micah