[llvm] ValueTracking/test: cover known-high-bits of rem (PR #109006)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 06:01:57 PDT 2024
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/109006
>From 7368130a586ea09ba27b527bf8fa82d14d0d9789 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 17 Sep 2024 16:38:32 +0100
Subject: [PATCH] ValueTracking/test: cover known-high-bits of rem
There is an underlying bug in KnownBits, and we should theoretically be
able to determine the high-bits of an srem as shown in the test, just
like urem. In preparation to fix this bug, add pre-commit tests testing
high-bits of srem and urem.
---
...wnbits-rem-lowbits.ll => knownbits-rem.ll} | 79 +++++++++++++++++++
1 file changed, 79 insertions(+)
rename llvm/test/Analysis/ValueTracking/{knownbits-rem-lowbits.ll => knownbits-rem.ll} (65%)
diff --git a/llvm/test/Analysis/ValueTracking/knownbits-rem-lowbits.ll b/llvm/test/Analysis/ValueTracking/knownbits-rem.ll
similarity index 65%
rename from llvm/test/Analysis/ValueTracking/knownbits-rem-lowbits.ll
rename to llvm/test/Analysis/ValueTracking/knownbits-rem.ll
index 0521c7130055fe..e5512fa71ae0e2 100644
--- a/llvm/test/Analysis/ValueTracking/knownbits-rem-lowbits.ll
+++ b/llvm/test/Analysis/ValueTracking/knownbits-rem.ll
@@ -12,6 +12,17 @@ define i8 @urem_low_bits_know(i8 %xx, i8 %yy) {
ret i8 %r
}
+define i8 @urem_high_bits_know(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @urem_high_bits_know(
+; CHECK-NEXT: ret i8 0
+;
+ %x = and i8 %xx, 2
+ %y = and i8 %yy, -4
+ %rem = urem i8 %x, %y
+ %r = and i8 %rem, 8
+ ret i8 %r
+}
+
define i8 @urem_low_bits_know2(i8 %xx, i8 %yy) {
; CHECK-LABEL: @urem_low_bits_know2(
; CHECK-NEXT: ret i8 2
@@ -91,6 +102,74 @@ define i8 @srem_low_bits_know2(i8 %xx, i8 %yy) {
ret i8 %r
}
+define i8 @srem_high_bits_know(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @srem_high_bits_know(
+; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], -2
+; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY:%.*]], -4
+; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], -2
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x = or i8 %xx, -2
+ %y = and i8 %yy, -4
+ %rem = srem i8 %x, %y
+ %r = and i8 %rem, -2
+ ret i8 %r
+}
+
+define i8 @srem_high_bits_know2(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @srem_high_bits_know2(
+; CHECK-NEXT: [[X:%.*]] = and i8 [[XX:%.*]], 13
+; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], -4
+; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], 8
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x = and i8 %xx, 13
+ %y = or i8 %yy, -4
+ %rem = srem i8 %x, %y
+ %r = and i8 %rem, 8
+ ret i8 %r
+}
+
+define i8 @srem_high_bits_know3(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @srem_high_bits_know3(
+; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], -13
+; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY:%.*]], 4
+; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], 8
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x = or i8 %xx, -13
+ %y = and i8 %yy, 4
+ %rem = srem i8 %x, %y
+ %r = and i8 %rem, 8
+ ret i8 %r
+}
+
+define i8 @srem_high_bits_know4(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @srem_high_bits_know4(
+; CHECK-NEXT: ret i8 0
+;
+ %x = and i8 %xx, 4
+ %y = or i8 %yy, -13
+ %rem = srem i8 %x, %y
+ %r = and i8 %rem, 8
+ ret i8 %r
+}
+
+define i8 @srem_high_bits_know5(i8 %xx, i8 %yy) {
+; CHECK-LABEL: @srem_high_bits_know5(
+; CHECK-NEXT: [[X:%.*]] = and i8 [[XX:%.*]], 2
+; CHECK-NEXT: ret i8 [[X]]
+;
+ %x = and i8 %xx, 2
+ %y = and i8 %yy, 4
+ %rem = srem i8 %x, %y
+ %r = and i8 %rem, 2
+ ret i8 %r
+}
+
define i8 @srem_todo_low_bits_partially_know_should_fold_out_srem(i8 %xx, i8 %yy) {
; CHECK-LABEL: @srem_todo_low_bits_partially_know_should_fold_out_srem(
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 10
More information about the llvm-commits
mailing list