Skip to content

Commit 7aa8a6b

Browse files
committed
[Xtnesa] Fix ConstantPool lowering.
Implement lowering of the aggregate and vector constants in Global Variables like it is done in gcc.
1 parent 42bc865 commit 7aa8a6b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,11 +1592,25 @@ SDValue XtensaTargetLowering::LowerConstantPool(SDValue Op,
15921592
SelectionDAG &DAG) const {
15931593
EVT PtrVT = Op.getValueType();
15941594
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
1595+
auto C = const_cast<Constant *>(CP->getConstVal());
1596+
auto T = const_cast<Type *>(CP->getType());
15951597
SDValue Result;
15961598

1597-
if (!CP->isMachineConstantPoolEntry()) {
1598-
Result = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, CP->getAlign(),
1599-
CP->getOffset());
1599+
// Do not use constant pool for aggregate or vector constant types,
1600+
// in such cases create global variable
1601+
if (T->isAggregateType() || T->isVectorTy()) {
1602+
auto AFI = DAG.getMachineFunction().getInfo<XtensaMachineFunctionInfo>();
1603+
auto M = const_cast<Module *>(
1604+
DAG.getMachineFunction().getFunction().getParent());
1605+
auto GV = new GlobalVariable(
1606+
*M, T, /*isConstant=*/true, GlobalVariable::InternalLinkage, C,
1607+
Twine(DAG.getDataLayout().getPrivateGlobalPrefix()) + "CP" +
1608+
Twine(DAG.getMachineFunction().getFunctionNumber()) + "_" +
1609+
Twine(AFI->createCPLabelId()));
1610+
Result = DAG.getTargetConstantPool(GV, PtrVT, Align(4));
1611+
} else if (!CP->isMachineConstantPoolEntry()) {
1612+
Result =
1613+
DAG.getTargetConstantPool(C, PtrVT, CP->getAlign(), CP->getOffset());
16001614
} else {
16011615
report_fatal_error("This constantpool type is not supported yet");
16021616
}

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ def : Pat<(i32 (extloadi1 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
310310
def : Pat<(i32 (extloadi8 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
311311
def : Pat<(i32 (extloadi16 addr_ish2:$addr)), (L16UI addr_ish2:$addr)>;
312312

313+
// Load from aggregate constant placed as Global Variable
314+
def : Pat<(i32 (load (add i32:$s, (Xtensa_pcrel_wrapper tconstpool:$in)))),
315+
(L32I (ADD i32:$s, (L32R tconstpool:$in)), 0)>;
316+
313317
//===----------------------------------------------------------------------===//
314318
// Conditional branch instructions
315319
//===----------------------------------------------------------------------===//
@@ -1661,6 +1665,11 @@ let AddedComplexity = 10 in
16611665
def : Pat<(f32 (load (Xtensa_pcrel_wrapper tconstpool:$in))),
16621666
(WFR (L32R tconstpool:$in))>;
16631667

1668+
// Load from aggregate constant placed as Global Variable
1669+
let AddedComplexity = 10 in
1670+
def : Pat<(f32 (load (add i32:$s, (Xtensa_pcrel_wrapper tconstpool:$in)))),
1671+
(LSI (ADD i32:$s, (L32R tconstpool:$in)), 0)>;
1672+
16641673
//===----------------------------------------------------------------------===//
16651674
// SelectCC and BranchCC instructions with FP operands
16661675
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)