[LLVMdev] RFC: CondCodeActions refactor (was RE: Why is this assertion here?)

Villmow, Micah Micah.Villmow at amd.com
Thu Jul 26 14:15:35 PDT 2012


Well, I found out the reason why this assert is here, and this is problematic.

CondCodeActions only supports up to 32 different value types. Since we are past 32, what LLVM has is broken.

Currently the 4 different Legalize states are stored in successive bits and packed into a uin64_t, see TargetLowering.h.
/// CondCodeActions - For each condition code (ISD::CondCode) keep a
  /// LegalizeAction that indicates how instruction selection should
  /// deal with the condition code.
  uint64_t CondCodeActions[ISD::SETCC_INVALID];

What I suggest is the following:
Change the definition of CondCodeAction to:
  uint64_t CondCodeActions[ISD::SETCC_INVALID][2];

setCondCodeAction then becomes:
void setCondCodeAction(ISD::CondCode CC, MVT VT,
                         LegalizeAction Action) {
    assert(VT < MVT::LAST_VALUETYPE &&
           (unsigned)CC < array_lengthof(CondCodeActions) &&
           "Table isn't big enough!");
    CondCodeActions[(unsigned)CC][VT.SimplyTy >> 5] &= ~(uint64_t(3UL)  << (VT.SimpleTy - 32)*2);
    CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5] |= (uint64_t)Action << (VT.SimpleTy - 32)*2;
  }

getCondCodeAction then becomes:
LegalizeAction
  getCondCodeAction(ISD::CondCode CC, EVT VT) const {
    assert((unsigned)CC < array_lengthof(CondCodeActions) &&
           (unsigned)VT.getSimpleVT().SimpleTy < MVT::LAST_VECTOR_VALUETYPE &&
           "Table isn't big enough!");
    LegalizeAction Action = (LegalizeAction)
      ((CondCodeActions[CC][VT.getSimpleVT().SimpleTy >> 5] >> (2*(VT.getSimpleVT().SimpleTy - 32))) & 3);
    assert(Action != Promote && "Can't promote condition code!");
    return Action;
  }


The other options are to use a BitVector, or to have a different array for each Legalized action. This approach however seems to use the minimum amount of memory/instructions.


Ideas?
Micah

From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Villmow, Micah
Sent: Thursday, July 26, 2012 11:29 AM
To: Developers Mailing List
Subject: [LLVMdev] Why is this assertion here?

I'm trying to understand why this assertion is here.
LegalizeAction
  getCondCodeAction(ISD::CondCode CC, EVT VT) const {
    assert((unsigned)CC < array_lengthof(CondCodeActions) &&
           (unsigned)VT.getSimpleVT().SimpleTy < sizeof(CondCodeActions[0])*4 &&
           "Table isn't big enough!");
    LegalizeAction Action = (LegalizeAction)
      ((CondCodeActions[CC] >> (2*VT.getSimpleVT().SimpleTy)) & 3);
    assert(Action != Promote && "Can't promote condition code!");
    return Action;
  }

The first part of the assertion I can understand, but why is there an assertion
that there are only 32 types? in TOT LLVM if this code is called with v8f32,v2f64
or v4f64, this assert is triggered.
Shouldn't the assert be:
(unsigned)VT.getSimpleVT().SimpleTy < MVT::MAX_ALLOWED_VALUETYPE &&
or
(unsigned)VT.getSimpleVT().SimpleTy < MVT::LAST_VECTOR_VALUETYPE &&
?

Thanks,
Micah


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120726/42e32429/attachment.html>


More information about the llvm-dev mailing list