Multiply i8 operands promotes to i32

Hello Pedro,

As others have said we’re assuming that you’re using Clang as the frontend, the MSP430TargetInfo class inside lib/Basic/Targets.cpp (clang codebase) set ints to be 16 bits wide, so you should get 16bit mults straight away without promotion. But anyways for 8bit multiplicantions you can do the following to bypass argument promotion:

  1. go to the lib/CodeGen/TargetInfo.cpp (clang codebase)

  2. implement a MSP430ABIInfo class derived from ABIInfo, check how other targets do it in the same file. The important part here is how you implement the classifyReturnType and classifyArgumentType functions, they should basically look like this:

class MSP430ABIInfo : public ABIInfo
{
public:
MSP430ABIInfo (CodeGenTypes &CGT) : ABIInfo(CGT) {}

ABIArgInfo classifyReturnType(QualType RetTy) const;
ABIArgInfo classifyArgumentType(QualType RetTy) const;

virtual void computeInfo(CGFunctionInfo &FI) const {
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
it != ie; ++it)
it->info = classifyArgumentType(it->type);
}

virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
CodeGenFunction &CGF) const { return 0; }
};

ABIArgInfo MSP430ABIInfo::classifyReturnType(QualType RetTy) const {
if (RetTy->isVoidType())
return ABIArgInfo::getIgnore();
if (isAggregateTypeForABI(RetTy))
return ABIArgInfo::getIndirect(0);

return ABIArgInfo::getDirect();
}

ABIArgInfo MSP430ABIInfo::classifyArgumentType(QualType Ty) const {
if (isAggregateTypeForABI(Ty))
return ABIArgInfo::getIndirect(0);

return ABIArgInfo::getDirect();
}

  1. Register your new MSP430ABIInfo class in the TargetCodeGenInfo constructor inside MSP430TargetCodeGenInfo by replacing DefaultABIInfo.

Hope this helps.

Hi,

I see this is a clang issue, and thanks for the reply. I guess this is
the path I should take right now to avoid to promote and truncate

Thanks,
Pedro