[PATCH] D107091: [Lanai] implement wide immediate support

Serge Bazanski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 29 10:47:26 PDT 2021


q3k created this revision.
Herald added a subscriber: hiraditya.
q3k requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107091

Files:
  llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
  llvm/test/CodeGen/Lanai/lowering-128.ll


Index: llvm/test/CodeGen/Lanai/lowering-128.ll
===================================================================
--- llvm/test/CodeGen/Lanai/lowering-128.ll
+++ llvm/test/CodeGen/Lanai/lowering-128.ll
@@ -12,3 +12,12 @@
   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
+}
+
Index: llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
===================================================================
--- llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
+++ llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
@@ -52,6 +52,16 @@
   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()))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107091.362824.patch
Type: text/x-patch
Size: 1424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210729/fb7a35cb/attachment.bin>


More information about the llvm-commits mailing list