[llvm] [InstCombine] Infer exact for lshr by cttz (PR #136696)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 06:14:01 PDT 2025
=?utf-8?b?6buD5ZyL5bqt?= <we3223 at gmail.com>,
=?utf-8?b?6buD5ZyL5bqt?= <we3223 at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/136696 at github.com>
================
@@ -0,0 +1,24 @@
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+declare i32 @llvm.cttz.i32(i32, i1)
+
+define i32 @test_cttz_lshr(i32 %x) {
+; CHECK-LABEL: @test_cttz_lshr(
+; CHECK: call range(i32 0, 33) i32 @llvm.cttz.i32(
+; CHECK: lshr exact i32
+; CHECK: ret i32
+ %cttz = call i32 @llvm.cttz.i32(i32 %x, i1 false)
+ %sh = lshr i32 %x, %cttz
+ ret i32 %sh
+}
+
+define i32 @test_cttz_ashr(i32 %x) {
+; CHECK-LABEL: @test_cttz_ashr(
+; CHECK: call range(i32 0, 33) i32 @llvm.cttz.i32(
+; CHECK: ashr exact i32
+; CHECK: ret i32
+ %cttz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
+ %sh = ashr i32 %x, %cttz
+ ret i32 %sh
+}
+
----------------
nikic wrote:
Please also add one negative test where the cttz operand is an unrelated value.
https://github.com/llvm/llvm-project/pull/136696
More information about the llvm-commits
mailing list