[llvm] [DAG] isKnownToBeAPowerOfTwo - Power of 2 value is known to be power of 2 after BSWAP/BITREVERSE (PR #182207)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 03:28:45 PST 2026


================
@@ -990,6 +1030,50 @@ define i32 @pow2_blsi_add(i32 %x, i32 %a) {
   ret i32 %r
 }
 
+
+; Test that (X + Y) & Y --> ~X & Y when Y = a & -a (pow2-or-zero).
+define i32 @pow2_rotl_orzero(i32 %x, i1 %c) {
+; CHECK-LABEL: pow2_rotl_orzero:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    notb %sil
+; CHECK-NEXT:    movzbl %sil, %eax
+; CHECK-NEXT:    andl $1, %eax
+; CHECK-NEXT:    addl %eax, %eax
+; CHECK-NEXT:    bswapl %eax
+; CHECK-NEXT:    roll $3, %eax
+; CHECK-NEXT:    notl %edi
+; CHECK-NEXT:    andl %edi, %eax
+; CHECK-NEXT:    retq
+  %y = select i1 %c, i32 0, i32 2
+  %d = call i32 @llvm.bswap.i32(i32 %y)
+  %rot_y = call i32 @llvm.fshl.i32(i32 %d, i32 %d, i32 3)
+  %x_add_y = add i32 %x, %rot_y
+  %r = and i32 %x_add_y, %rot_y
+  ret i32 %r
+}
----------------
RKSimon wrote:

drop the rot tests

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


More information about the llvm-commits mailing list