GlobalISel: respect BooleanContents when extending i1.

The world isn't just x86 & ARM, some targets need to store -1 into the byte
when legalizing a bool store.

llvm-svn: 298453
This commit is contained in:
Tim Northover 2017-03-21 22:22:05 +00:00
parent 5b20fbb748
commit 548feeecd3

View File

@ -428,12 +428,24 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
return Legalized;
}
case TargetOpcode::G_STORE: {
assert(alignTo(MRI.getType(MI.getOperand(0).getReg()).getSizeInBits(), 8) ==
WideTy.getSizeInBits() &&
"illegal to increase number of bytes modified by a store");
if (MRI.getType(MI.getOperand(0).getReg()) != LLT::scalar(1) ||
WideTy != LLT::scalar(8))
return UnableToLegalize;
auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
auto Content = TLI.getBooleanContents(false, false);
unsigned ExtOp = TargetOpcode::G_ANYEXT;
if (Content == TargetLoweringBase::ZeroOrOneBooleanContent)
ExtOp = TargetOpcode::G_ZEXT;
else if (Content == TargetLoweringBase::ZeroOrNegativeOneBooleanContent)
ExtOp = TargetOpcode::G_SEXT;
else
ExtOp = TargetOpcode::G_ANYEXT;
unsigned SrcExt = MRI.createGenericVirtualRegister(WideTy);
MIRBuilder.buildZExt(SrcExt, MI.getOperand(0).getReg());
MIRBuilder.buildInstr(ExtOp).addDef(SrcExt).addUse(
MI.getOperand(0).getReg());
MIRBuilder.buildStore(SrcExt, MI.getOperand(1).getReg(),
**MI.memoperands_begin());
MI.eraseFromParent();