Skip to content

Commit

Permalink
[ValueTracking] Pass exact flag to KnownBits::udiv in `computeKno…
Browse files Browse the repository at this point in the history
…wnBits`

This information was previously missing but we can use it for
determining the low-bits.

Differential Revision: https://reviews.llvm.org/D150095
  • Loading branch information
goldsteinn committed May 16, 2023
1 parent 7d05ab9 commit 99795af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
case Instruction::UDiv: {
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::udiv(Known, Known2);
Known =
KnownBits::udiv(Known, Known2, Q.IIQ.isExact(cast<BinaryOperator>(I)));
break;
}
case Instruction::Select: {
Expand Down
14 changes: 2 additions & 12 deletions llvm/test/Analysis/ValueTracking/knownbits-div.ll
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ define i1 @udiv_high_bits(i8 %x, i8 %y) {

define i1 @udiv_exact_odd_odd(i8 %x, i8 %y) {
; CHECK-LABEL: @udiv_exact_odd_odd(
; CHECK-NEXT: [[NUM:%.*]] = or i8 [[X:%.*]], 1
; CHECK-NEXT: [[DENUM:%.*]] = or i8 [[Y:%.*]], 1
; CHECK-NEXT: [[DIV:%.*]] = udiv exact i8 [[NUM]], [[DENUM]]
; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 false
;
%num = or i8 %x, 1
%denum = or i8 %y, 1
Expand All @@ -214,12 +209,7 @@ define i1 @udiv_exact_odd_odd(i8 %x, i8 %y) {

define i1 @udiv_exact_even_odd(i8 %x, i8 %y) {
; CHECK-LABEL: @udiv_exact_even_odd(
; CHECK-NEXT: [[NUM:%.*]] = and i8 [[X:%.*]], -2
; CHECK-NEXT: [[DENUM:%.*]] = or i8 [[Y:%.*]], 1
; CHECK-NEXT: [[DIV:%.*]] = udiv exact i8 [[NUM]], [[DENUM]]
; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 1
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 false
;
%num = and i8 %x, -2
%denum = or i8 %y, 1
Expand Down

0 comments on commit 99795af

Please sign in to comment.