[llvm] [LegalizeTypes] Keep non-negative info in SUB(CTLZ) (PR #186338)
Alexey Merzlyakov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 05:50:38 PDT 2026
================
@@ -0,0 +1,43 @@
+; RUN: llc -O1 -mtriple=aarch64-linux-gnu %s -o - 2>&1 | FileCheck %s
+;
+; Test ensures that the compiler generates no extra instructions
+; for __builtin_clzg output type conversion
+;
+; IR for this test was generated from the following source code:
+; #include <stdint.h>
+; int32_t foo8(uint8_t x) { return __builtin_clzg(x); }
+; int32_t foo16(uint16_t x) { return __builtin_clzg(x); }
+
+; CHECK-LABEL: foo8:
+; CHECK: %bb.0:
+; CHECK-NEXT: and w8, w0, #0xff
+; CHECK-NEXT: clz w8, w8
+; CHECK-NEXT: sub w0, w8, #24
+; CHECK-NEXT: ret
+define dso_local range(i32 0, 9) i32 @foo8(i8 noundef %0) local_unnamed_addr #0 {
----------------
AlexeyMerzlyakov wrote:
Done in https://github.com/llvm/llvm-project/pull/186338/changes/221ab952198d41bc71b78df8ec32d38786a1d177. GlobalISel seem to not have this optimization yet, so we have double-generated checks for each instruction selection method.
https://github.com/llvm/llvm-project/pull/186338
More information about the llvm-commits
mailing list