[Lanai] implement wide immediate support

This fixes LanaiTTIImpl::getIntImmCost to return valid costs for i128
(and wider) values. Previously any immediate wider than
64 bits would cause Lanai llc to crash.

A regression test is also added that exercises this functionality.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D107091
This commit is contained in:
Serge Bazanski 2021-09-10 10:54:43 +00:00 committed by whitequark
parent 231bfaab31
commit 788e7b3b8c
2 changed files with 19 additions and 0 deletions

View File

@ -52,6 +52,16 @@ public:
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
TTI::TargetCostKind CostKind) { TTI::TargetCostKind CostKind) {
assert(Ty->isIntegerTy()); assert(Ty->isIntegerTy());
unsigned BitSize = Ty->getPrimitiveSizeInBits();
// There is no cost model for constants with a bit size of 0. Return
// TCC_Free here, so that constant hoisting will ignore this constant.
if (BitSize == 0)
return TTI::TCC_Free;
// No cost model for operations on integers larger than 64 bit implemented
// yet.
if (BitSize > 64)
return TTI::TCC_Free;
if (Imm == 0) if (Imm == 0)
return TTI::TCC_Free; return TTI::TCC_Free;
if (isInt<16>(Imm.getSExtValue())) if (isInt<16>(Imm.getSExtValue()))

View File

@ -11,3 +11,12 @@ define i128 @add128(i128 %x, i128 %y) {
%a = add i128 %x, %y %a = add i128 %x, %y
ret i128 %a ret i128 %a
} }
; CHECK-LABEL: immshift128:
define i128 @immshift128(i1 %sel) unnamed_addr {
%a = add i128 0, 340282366920938463463374007431768209319
%b = add i128 0, 340282366920938463463374607431768209320
%c = select i1 %sel, i128 %a, i128 %b
%d = shl i128 %a, 10
ret i128 %d
}