mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-03 16:18:37 +00:00
Revert "[ValueTracking] Understand more select patterns in ComputeKnownBits"
This reverts commit r257769. Backing this out because of stage2 failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257773 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
edec0136f0
commit
def08208bf
@ -1140,52 +1140,14 @@ static void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero,
|
|||||||
KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ);
|
KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Select: {
|
case Instruction::Select:
|
||||||
computeKnownBits(I->getOperand(2), KnownZero, KnownOne, DL, Depth + 1, Q);
|
computeKnownBits(I->getOperand(2), KnownZero, KnownOne, DL, Depth + 1, Q);
|
||||||
computeKnownBits(I->getOperand(1), KnownZero2, KnownOne2, DL, Depth + 1, Q);
|
computeKnownBits(I->getOperand(1), KnownZero2, KnownOne2, DL, Depth + 1, Q);
|
||||||
|
|
||||||
// Only known if known in both the LHS and RHS.
|
// Only known if known in both the LHS and RHS.
|
||||||
KnownOne &= KnownOne2;
|
KnownOne &= KnownOne2;
|
||||||
KnownZero &= KnownZero2;
|
KnownZero &= KnownZero2;
|
||||||
|
|
||||||
// There are several cmp+select patterns that ensure their result will be no
|
|
||||||
// greater than a constant. Detect a number of these.
|
|
||||||
Value *X, *Y;
|
|
||||||
ConstantInt *C1, *C2;
|
|
||||||
ICmpInst::Predicate Pred;
|
|
||||||
|
|
||||||
auto IsLessThanOrEqualTo = [](Value *X, Value *Y) {
|
|
||||||
if (X == Y)
|
|
||||||
return true;
|
|
||||||
Value *M1, *M2;
|
|
||||||
ConstantInt *C1, *C2;
|
|
||||||
if (!match(X, m_NSWAdd(m_Value(M1), m_ConstantInt(C1))))
|
|
||||||
C1 = nullptr;
|
|
||||||
if (!match(Y, m_NSWAdd(m_Value(M2), m_ConstantInt(C2))))
|
|
||||||
C2 = nullptr;
|
|
||||||
if (C1 && M1 == Y && C1->isNegative())
|
|
||||||
return true;
|
|
||||||
if (C2 && M2 == X && !C2->isNegative())
|
|
||||||
return true;
|
|
||||||
if (C1 && C2 && M1 == M2 && !C1->isNegative() && !C2->isNegative() &&
|
|
||||||
C1->getValue().ule(C2->getValue()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// (select (icmp ugt X, C1), C2, Y)
|
|
||||||
// if Y <= X and C2 <= C1
|
|
||||||
// then maximum value = C1.
|
|
||||||
if (match(I, m_Select(m_ICmp(Pred, m_Value(X), m_ConstantInt(C1)),
|
|
||||||
m_ConstantInt(C2), m_Value(Y)))) {
|
|
||||||
if (Pred == ICmpInst::ICMP_UGT && IsLessThanOrEqualTo(Y, X) &&
|
|
||||||
C2->getValue().ule(C1->getValue())) {
|
|
||||||
auto V = cast<ConstantInt>(C1)->getValue() - 1;
|
|
||||||
KnownZero = ~APInt::getLowBitsSet(V.getBitWidth(), V.getActiveBits());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case Instruction::FPTrunc:
|
case Instruction::FPTrunc:
|
||||||
case Instruction::FPExt:
|
case Instruction::FPExt:
|
||||||
case Instruction::FPToUI:
|
case Instruction::FPToUI:
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
; RUN: opt -S -instsimplify < %s | FileCheck %s
|
|
||||||
|
|
||||||
; CHECK-LABEL: @one
|
|
||||||
define i32 @one(i32 %a) {
|
|
||||||
; CHECK: ret i32 0
|
|
||||||
%b = icmp ugt i32 %a, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %a
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @two
|
|
||||||
define i32 @two(i32 %a) {
|
|
||||||
; CHECK: ret i32 0
|
|
||||||
%x = add nsw i32 %a, 4
|
|
||||||
%b = icmp ugt i32 %x, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %a
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @two_no_nsw
|
|
||||||
define i32 @two_no_nsw(i32 %a) {
|
|
||||||
; CHECK: ret i32 %d
|
|
||||||
%x = add i32 %a, 4
|
|
||||||
%b = icmp ugt i32 %x, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %a
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @three
|
|
||||||
define i32 @three(i32 %a) {
|
|
||||||
; CHECK: ret i32 0
|
|
||||||
%x = add nsw i32 %a, -4
|
|
||||||
%b = icmp ugt i32 %a, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %x
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @four
|
|
||||||
define i32 @four(i32 %a) {
|
|
||||||
; CHECK: ret i32 0
|
|
||||||
%x = add nsw i32 %a, 42
|
|
||||||
%y = add nsw i32 %a, 64
|
|
||||||
%b = icmp ugt i32 %y, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %x
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @four_swapped
|
|
||||||
define i32 @four_swapped(i32 %a) {
|
|
||||||
; CHECK: ret i32 %d
|
|
||||||
%x = add nsw i32 %a, 42
|
|
||||||
%y = add nsw i32 %a, 64
|
|
||||||
%b = icmp ugt i32 %x, 5
|
|
||||||
%c = select i1 %b, i32 2, i32 %y
|
|
||||||
%d = lshr i32 %c, 24
|
|
||||||
ret i32 %d
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user