[PATCH] D128911: Emit table lookup from TargetLowering::expandCTTZ()
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 24 08:29:44 PDT 2022
dmgreen added inline comments.
================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:7814-7819
+ for (unsigned int i = 0; i < NumBitsPerElt; i++) {
+ SDValue Index = DAG.getConstant(RshrArr[i], dl, VT);
+ ConstantSDNode *IndexNode = cast<ConstantSDNode>(Index);
+ ConstantInt *CI =
+ const_cast<ConstantInt *>(IndexNode->getConstantIntValue());
+ Elts.push_back(CI);
----------------
gsocshubham wrote:
> dmgreen wrote:
> > Do we need this loop, or can we create the array from the constant pool directly? The elements should be MVT::i8.
> > ```
> > auto *CA = ConstantDataArray::get(*DAG.getContext(), RshrArr);
> > ```
> If I directly use `RshrArr`, I get below table in assembly -
>
> ```
> .LCPI0_0:
> .ascii "\000\001\034\002\035\016\030\003\036\026\024\017\031\021\004\b\037\033\r\027\025\023\020\007\032\f\022\006\013\005\n\t"
> ```
>
> instead of -
>
> ```
> .LCPI0_0:
> .word 0 ! 0x0
> .word 1 ! 0x1
> .word 28 ! 0x1c
> .word 2 ! 0x2
> .word 29 ! 0x1d
> .word 14 ! 0xe
> .word 24 ! 0x18
> .word 3 ! 0x3
> .word 30 ! 0x1e
> .word 22 ! 0x16
> .word 20 ! 0x14
> .word 15 ! 0xf
> .word 25 ! 0x19
> .word 17 ! 0x11
> .word 4 ! 0x4
> .word 8 ! 0x8
> .word 31 ! 0x1f
> .word 27 ! 0x1b
> .word 13 ! 0xd
> .word 23 ! 0x17
> .word 21 ! 0x15
> .word 19 ! 0x13
> .word 16 ! 0x10
> .word 7 ! 0x7
> .word 26 ! 0x1a
> .word 12 ! 0xc
> .word 18 ! 0x12
> .word 6 ! 0x6
> .word 11 ! 0xb
> .word 5 ! 0x5
> .word 10 ! 0xa
> .word 9 ! 0x9
> .text
> .globl f
>
> ```
Yes - that seems better to be, so long as it is loading i8's from the array. The .word's will be i32 I think, which uses much more data than it needs, as all the values are in the range 0-BitWidth.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128911/new/
https://reviews.llvm.org/D128911
More information about the llvm-commits
mailing list