[llvm] d294e3c - [SelectionDAG] Improve `computeKnownBits` implementations of `sdiv` and `udiv`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 16:58:50 PDT 2023
Author: Noah Goldstein
Date: 2023-05-16T18:58:13-05:00
New Revision: d294e3cb763abd33fcabf1e3642cb6659fd304cf
URL: https://github.com/llvm/llvm-project/commit/d294e3cb763abd33fcabf1e3642cb6659fd304cf
DIFF: https://github.com/llvm/llvm-project/commit/d294e3cb763abd33fcabf1e3642cb6659fd304cf.diff
LOG: [SelectionDAG] Improve `computeKnownBits` implementations of `sdiv` and `udiv`
Add `exact` flag handling for `udiv` and add entire `sdiv` case.
Differential Revision: https://reviews.llvm.org/D150098
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/ARM/select-imm.ll
llvm/test/CodeGen/X86/knownbits-div.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 619df8a0d56d..ffa9998949b4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3700,7 +3700,13 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
case ISD::UDIV: {
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
- Known = KnownBits::udiv(Known, Known2);
+ Known = KnownBits::udiv(Known, Known2, Op->getFlags().hasExact());
+ break;
+ }
+ case ISD::SDIV: {
+ Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+ Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
+ Known = KnownBits::sdiv(Known, Known2, Op->getFlags().hasExact());
break;
}
case ISD::SREM: {
diff --git a/llvm/test/CodeGen/ARM/select-imm.ll b/llvm/test/CodeGen/ARM/select-imm.ll
index fcfbc318ed2a..65288e1884c7 100644
--- a/llvm/test/CodeGen/ARM/select-imm.ll
+++ b/llvm/test/CodeGen/ARM/select-imm.ll
@@ -657,9 +657,12 @@ define i1 @t10() {
; V8MBASE-NEXT: movs r0, #7
; V8MBASE-NEXT: mvns r0, r0
; V8MBASE-NEXT: str r0, [sp]
-; V8MBASE-NEXT: adds r0, r0, #5
-; V8MBASE-NEXT: str r0, [sp, #4]
-; V8MBASE-NEXT: movs r1, #0
+; V8MBASE-NEXT: adds r1, r0, #5
+; V8MBASE-NEXT: str r1, [sp, #4]
+; V8MBASE-NEXT: sdiv r2, r1, r0
+; V8MBASE-NEXT: muls r2, r0, r2
+; V8MBASE-NEXT: subs r0, r1, r2
+; V8MBASE-NEXT: subs r1, r0, r1
; V8MBASE-NEXT: rsbs r0, r1, #0
; V8MBASE-NEXT: adcs r0, r1
; V8MBASE-NEXT: add sp, #8
diff --git a/llvm/test/CodeGen/X86/knownbits-div.ll b/llvm/test/CodeGen/X86/knownbits-div.ll
index 0c8501ff9eb4..02e20a9010cc 100644
--- a/llvm/test/CodeGen/X86/knownbits-div.ll
+++ b/llvm/test/CodeGen/X86/knownbits-div.ll
@@ -4,11 +4,7 @@
define i8 @sdiv_neg_neg_high_bits(i8 %x, i8 %y) {
; CHECK-LABEL: sdiv_neg_neg_high_bits:
; CHECK: # %bb.0:
-; CHECK-NEXT: orb $-128, %dil
-; CHECK-NEXT: orb $-125, %sil
-; CHECK-NEXT: movsbl %dil, %eax
-; CHECK-NEXT: idivb %sil
-; CHECK-NEXT: andb $-128, %al
+; CHECK-NEXT: xorl %eax, %eax
; CHECK-NEXT: retq
%num = or i8 %x, 128
%denum = or i8 %y, 131
@@ -20,11 +16,7 @@ define i8 @sdiv_neg_neg_high_bits(i8 %x, i8 %y) {
define i8 @sdiv_exact_odd_odd(i8 %x, i8 %y) {
; CHECK-LABEL: sdiv_exact_odd_odd:
; CHECK: # %bb.0:
-; CHECK-NEXT: orb $1, %dil
-; CHECK-NEXT: orb $1, %sil
-; CHECK-NEXT: movsbl %dil, %eax
-; CHECK-NEXT: idivb %sil
-; CHECK-NEXT: andb $1, %al
+; CHECK-NEXT: movb $1, %al
; CHECK-NEXT: retq
%num = or i8 %x, 1
%denum = or i8 %y, 1
@@ -52,11 +44,7 @@ define i8 @sdiv_exact_even_even_fail_unknown(i8 %x, i8 %y) {
define i8 @udiv_exact_even_odd(i8 %x, i8 %y) {
; CHECK-LABEL: udiv_exact_even_odd:
; CHECK: # %bb.0:
-; CHECK-NEXT: andb $-2, %dil
-; CHECK-NEXT: orb $1, %sil
-; CHECK-NEXT: movzbl %dil, %eax
-; CHECK-NEXT: divb %sil
-; CHECK-NEXT: andb $1, %al
+; CHECK-NEXT: xorl %eax, %eax
; CHECK-NEXT: retq
%num = and i8 %x, -2
%denum = or i8 %y, 1
More information about the llvm-commits
mailing list