mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00:00
[InstCombine] replace divide-by-constant checks with asserts; NFC
These folds already have tests for scalar and vector types, except for the vector div-by-0 case, so I'm adding tests for that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280115 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bb0403b31b
commit
f097e134b1
@ -1971,15 +1971,6 @@ Instruction *InstCombiner::foldICmpUDivConstant(ICmpInst &Cmp,
|
|||||||
Instruction *InstCombiner::foldICmpDivConstant(ICmpInst &Cmp,
|
Instruction *InstCombiner::foldICmpDivConstant(ICmpInst &Cmp,
|
||||||
BinaryOperator *Div,
|
BinaryOperator *Div,
|
||||||
const APInt *C) {
|
const APInt *C) {
|
||||||
// FIXME: These checks restrict all folds under here to scalar types.
|
|
||||||
ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
|
|
||||||
if (!RHS)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
ConstantInt *DivRHS = dyn_cast<ConstantInt>(Div->getOperand(1));
|
|
||||||
if (!DivRHS)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// Fold: icmp pred ([us]div X, C2), C -> range test
|
// Fold: icmp pred ([us]div X, C2), C -> range test
|
||||||
// Fold this div into the comparison, producing a range check.
|
// Fold this div into the comparison, producing a range check.
|
||||||
// Determine, based on the divide type, what the range is being
|
// Determine, based on the divide type, what the range is being
|
||||||
@ -2002,16 +1993,22 @@ Instruction *InstCombiner::foldICmpDivConstant(ICmpInst &Cmp,
|
|||||||
if (!Cmp.isEquality() && DivIsSigned != Cmp.isSigned())
|
if (!Cmp.isEquality() && DivIsSigned != Cmp.isSigned())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// FIXME: These 3 checks can be asserts.
|
// These constant divides should already be folded in InstSimplify.
|
||||||
if (*C2 == 0)
|
assert(*C2 != 0 && "The ProdOV computation fails on divide by zero.");
|
||||||
return nullptr; // The ProdOV computation fails on divide by zero.
|
assert(*C2 != 1 && "Funny cases with INT_MIN will fail.");
|
||||||
if (DivIsSigned && C2->isAllOnesValue())
|
|
||||||
return nullptr; // The overflow computation also screws up here
|
// This constant divide should already be folded in InstCombine.
|
||||||
if (*C2 == 1) {
|
assert(!(DivIsSigned && C2->isAllOnesValue()) &&
|
||||||
// This eliminates some funny cases with INT_MIN.
|
"The overflow computation will fail.");
|
||||||
Cmp.setOperand(0, Div->getOperand(0)); // X/1 == X.
|
|
||||||
return &Cmp;
|
// FIXME: These checks restrict all folds under here to scalar types.
|
||||||
}
|
ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
|
||||||
|
if (!RHS)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
ConstantInt *DivRHS = dyn_cast<ConstantInt>(Div->getOperand(1));
|
||||||
|
if (!DivRHS)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
// Compute Prod = CI * DivRHS. We are essentially solving an equation
|
// Compute Prod = CI * DivRHS. We are essentially solving an equation
|
||||||
// of form X/C2=C. We solve for X by multiplying C2 (DivRHS) and
|
// of form X/C2=C. We solve for X by multiplying C2 (DivRHS) and
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
; NOTE: Assertions have been autogenerated by update_test_checks.py
|
|
||||||
; RUN: opt -instsimplify -S < %s | FileCheck %s
|
; RUN: opt -instsimplify -S < %s | FileCheck %s
|
||||||
|
|
||||||
define i64 @test0() {
|
define i64 @test0() {
|
||||||
@ -194,6 +193,14 @@ define i32 @test20(i32 %a) {
|
|||||||
ret i32 %b
|
ret i32 %b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define <2 x i32> @test20vec(<2 x i32> %a) {
|
||||||
|
; CHECK-LABEL: @test20vec(
|
||||||
|
; CHECK-NEXT: ret <2 x i32> undef
|
||||||
|
;
|
||||||
|
%b = udiv <2 x i32> %a, zeroinitializer
|
||||||
|
ret <2 x i32> %b
|
||||||
|
}
|
||||||
|
|
||||||
define i32 @test21(i32 %a) {
|
define i32 @test21(i32 %a) {
|
||||||
; CHECK-LABEL: @test21(
|
; CHECK-LABEL: @test21(
|
||||||
; CHECK: ret i32 undef
|
; CHECK: ret i32 undef
|
||||||
@ -202,6 +209,14 @@ define i32 @test21(i32 %a) {
|
|||||||
ret i32 %b
|
ret i32 %b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define <2 x i32> @test21vec(<2 x i32> %a) {
|
||||||
|
; CHECK-LABEL: @test21vec(
|
||||||
|
; CHECK-NEXT: ret <2 x i32> undef
|
||||||
|
;
|
||||||
|
%b = sdiv <2 x i32> %a, zeroinitializer
|
||||||
|
ret <2 x i32> %b
|
||||||
|
}
|
||||||
|
|
||||||
define i32 @test22(i32 %a) {
|
define i32 @test22(i32 %a) {
|
||||||
; CHECK-LABEL: @test22(
|
; CHECK-LABEL: @test22(
|
||||||
; CHECK: ret i32 undef
|
; CHECK: ret i32 undef
|
||||||
|
Loading…
Reference in New Issue
Block a user