[PATCH] D128911: Emit table lookup from TargetLowering::expandCTTZ()

Shubham Narlawar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 05:06:16 PDT 2022


gsocshubham added a comment.

For the SPARC backend, there is no CTTZ or CTLZ support.

  @f.table = internal unnamed_addr constant [32 x i8] c"\00\01\1C\02\1D\0E\18\03\1E\16\14\0F\19\11\04\08\1F\1B\0D\17\15\13\10\07\1A\0C\12\06\0B\05\0A\09", align 1
  
  define i32 @f(i32 %x) {
  entry:
    %0 = call i32 @llvm.cttz.i32(i32 %x, i1 true)
    %1 = icmp eq i32 %x, 0
    %2 = select i1 %1, i32 0, i32 %0
    %3 = trunc i32 %2 to i8
    %conv = zext i8 %3 to i32
    ret i32 %conv
  }

Above changes generates below assembly -

          .file   "ctz.ll"
          .section        .rodata,#alloc
          .p2align        2                               ! -- Begin function f
  .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
          .p2align        2
          .type   f, at function
  f:                                      ! @f
          .cfi_startproc
  ! %bb.0:                                ! %entry
          mov     %o0, %o1
          cmp %o0, 0
          be      .LBB0_2
          mov     %g0, %o0
  ! %bb.1:                                ! %entry
          sub %o0, %o1, %o0
          and %o1, %o0, %o0
          sethi 122669, %o1
          or %o1, 305, %o1
          smul %o0, %o1, %o0
          srl %o0, 27, %o0
          sethi %hi(.LCPI0_0), %o1
          ld [%o1+%lo(.LCPI0_0)], %o0
  .LBB0_2:                                ! %entry
          retl
          nop
  .Lfunc_end0:
          .size   f, .Lfunc_end0-f
          .cfi_endproc
                                          ! -- End function
          .type   f.table, at object                 ! @f.table
          .section        .rodata.cst32,"aM", at progbits,32
  f.table:
          .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"
          .size   f.table, 32


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128911/new/

https://reviews.llvm.org/D128911



More information about the llvm-commits mailing list