[LLVMdev] MBlaze select_cc lowering question.

Stefan Kristiansson stefan.kristiansson at saunalahti.fi
Mon Aug 20 22:05:01 PDT 2012


On Sun, Aug 19, 2012 at 3:11 PM, JP
<jpbonn-keyword-llvm.7c175e at corniceresearch.com> wrote:
> Can someone explain how the condition code is passed from the
> MBlazeTargetLowering::LowerSELECT_CC to
> MBlazeTargetLowering::EmitCustomSelect custom inserter? In
> LowerSELECT_CC the condition code is never accessed (Op.GetOperand(4))
> and I don't see how it ends up getting correctly passed to the
> MBlazeTargetLowering::EmitCustomSelect.
>
>> SDValue MBlazeTargetLowering::LowerSELECT_CC(SDValue Op,
>>                                              SelectionDAG &DAG) const {
>>   SDValue LHS = Op.getOperand(0);
>>   SDValue RHS = Op.getOperand(1);
>>   SDValue TrueVal = Op.getOperand(2);
>>   SDValue FalseVal = Op.getOperand(3);
>>   DebugLoc dl = Op.getDebugLoc();
>>   unsigned Opc;
>>
>>   SDValue CompareFlag;
>>   if (LHS.getValueType() == MVT::i32) {
>>     Opc = MBlazeISD::Select_CC;
>>     CompareFlag = DAG.getNode(MBlazeISD::ICmp, dl, MVT::i32, LHS, RHS)
>>                     .getValue(1);
>>   } else {
>>     llvm_unreachable("Cannot lower select_cc with unknown type");
>>   }
>>
>>   return DAG.getNode(Opc, dl, TrueVal.getValueType(), TrueVal, FalseVal,
>>                      CompareFlag);
>> }

The Microblaze code is far from obvious in that regard and I can't claim to be
overly familiar with it, but here's my understanding of what's going on:
LowerSELECT_CC() is actually not used; notice that there are no
custom operation action set for it. Instead the condition codes
are picked in MBlazeInstrInfo.td with pattern matching using
"magic" numbers to pick the correct MBlazeCC enum.
E.g.
// SELECT_CC
def : Pat<(selectcc (i32 GPR:$L), (i32 0),
                    (i32 GPR:$T), (i32 GPR:$F), SETEQ),
          (Select_CC GPR:$T, GPR:$F, GPR:$L, 1)>;

where the '1' = MBlazeCC::EQ

Stefan



More information about the llvm-dev mailing list