[llvm] 788e7b3 - [Lanai] implement wide immediate support
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 03:55:38 PDT 2021
Author: Serge Bazanski
Date: 2021-09-10T10:54:43Z
New Revision: 788e7b3b8c285d63a4ef354608240e1376179c79
URL: https://github.com/llvm/llvm-project/commit/788e7b3b8c285d63a4ef354608240e1376179c79
DIFF: https://github.com/llvm/llvm-project/commit/788e7b3b8c285d63a4ef354608240e1376179c79.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
llvm/test/CodeGen/Lanai/lowering-128.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h b/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
index f1fcbe4f418ac..3ad41c57ac2c3 100644
--- a/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
+++ b/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
@@ -52,6 +52,16 @@ class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
TTI::TargetCostKind CostKind) {
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)
return TTI::TCC_Free;
if (isInt<16>(Imm.getSExtValue()))
diff --git a/llvm/test/CodeGen/Lanai/lowering-128.ll b/llvm/test/CodeGen/Lanai/lowering-128.ll
index dbd08095aeac7..98fb5ece65c0b 100644
--- a/llvm/test/CodeGen/Lanai/lowering-128.ll
+++ b/llvm/test/CodeGen/Lanai/lowering-128.ll
@@ -11,3 +11,12 @@ define i128 @add128(i128 %x, i128 %y) {
%a = add i128 %x, %y
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
+}
More information about the llvm-commits
mailing list