From 99795afb28af4a93e128597b47579e05da2340b3 Mon Sep 17 00:00:00 2001 From: Noah Goldstein Date: Sat, 6 May 2023 21:04:31 -0500 Subject: [PATCH] [ValueTracking] Pass `exact` flag to `KnownBits::udiv` in `computeKnownBits` This information was previously missing but we can use it for determining the low-bits. Differential Revision: https://reviews.llvm.org/D150095 --- llvm/lib/Analysis/ValueTracking.cpp | 3 ++- llvm/test/Analysis/ValueTracking/knownbits-div.ll | 14 ++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 2862e42..77b99f9 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -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(I))); break; } case Instruction::Select: { diff --git a/llvm/test/Analysis/ValueTracking/knownbits-div.ll b/llvm/test/Analysis/ValueTracking/knownbits-div.ll index 586d3af..15e1ac9 100644 --- a/llvm/test/Analysis/ValueTracking/knownbits-div.ll +++ b/llvm/test/Analysis/ValueTracking/knownbits-div.ll @@ -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 @@ -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 -- 2.7.4