[llvm] Optimize count leading ones if promoted type (PR #99591)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 13:04:45 PDT 2024


================
@@ -0,0 +1,100 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s --mtriple=aarch64 -verify-machineinstrs | FileCheck %s
+; RUN: llc < %s --mtriple=aarch64 -global-isel -verify-machineinstrs | FileCheck %s
+
+declare i8 @llvm.ctlz.i8(i8, i1)
+declare i16 @llvm.ctlz.i16(i16, i1)
+declare i32 @llvm.ctlz.i32(i32, i1)
+declare i64 @llvm.ctlz.i64(i64, i1)
+
+define i8 @ctlo_i8(i8 %x) {
+; CHECK-LABEL: ctlo_i8:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    mov w8, #-1 // =0xffffffff
+; CHECK-NEXT:    eor w8, w8, w0, lsl #24
+; CHECK-NEXT:    clz w0, w8
+; CHECK-NEXT:    ret
+  %tmp1 = xor i8 %x, -1
+  %tmp2 = call i8 @llvm.ctlz.i8( i8 %tmp1, i1 false )
+  ret i8 %tmp2
+}
+
+define i8 @ctlo_i8_undef(i8 %x) {
+; CHECK-LABEL: ctlo_i8_undef:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    mov w8, #-1 // =0xffffffff
----------------
topperc wrote:

This looks worse than the current codegen

```
ctlo_i8_undef:                          // @ctlo_i8_undef                        
        .cfi_startproc                                                           
// %bb.0:                                                                        
        mvn     w8, w0                                                           
        lsl     w8, w8, #24                                                      
        clz     w0, w8                                                           
        ret
```

https://github.com/llvm/llvm-project/pull/99591


More information about the llvm-commits mailing list