[llvm] [ValueTracking] Infer is-power-of-2 from assumptions. (PR #107745)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 8 12:03:58 PDT 2024
================
@@ -1041,3 +1041,19 @@ define <2 x i32> @PR62401(<2 x i1> %x, <2 x i32> %y) {
%r = urem <2 x i32> %y, %sext.i1
ret <2 x i32> %r
}
+
+define i16 @rem_pow2(i16 %x, i16 %y) {
+; CHECK-LABEL: @rem_pow2(
+; CHECK-NEXT: [[POPCNT:%.*]] = tail call range(i16 1, 17) i16 @llvm.ctpop.i16(i16 [[Y:%.*]])
+; CHECK-NEXT: [[COND:%.*]] = icmp ult i16 [[POPCNT]], 2
+; CHECK-NEXT: tail call void @llvm.assume(i1 [[COND]])
+; CHECK-NEXT: [[TMP1:%.*]] = add i16 [[Y]], -1
+; CHECK-NEXT: [[REM:%.*]] = and i16 [[X:%.*]], [[TMP1]]
+; CHECK-NEXT: ret i16 [[REM]]
+;
+ %popcnt = tail call i16 @llvm.ctpop.i16(i16 %y)
+ %cond = icmp sle i16 %popcnt, 1
+ tail call void @llvm.assume(i1 %cond)
+ %rem = urem i16 %x, %y
+ ret i16 %rem
+}
----------------
nikic wrote:
Can you please also test the == case here, to confirm that both work?
https://github.com/llvm/llvm-project/pull/107745
More information about the llvm-commits
mailing list