1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

InstSimplify: div %X, 0 -> undef

We already optimized rem %X, 0 to undef, we should do the same for div.

llvm-svn: 223919
This commit is contained in:
David Majnemer 2014-12-10 07:52:18 +00:00
parent c4b33849c6
commit 8ec2668c75
2 changed files with 18 additions and 0 deletions

View File

@ -1011,6 +1011,10 @@ static Value *SimplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
if (match(Op1, m_Undef()))
return Op1;
// X / 0 -> undef, we don't need to preserve faults!
if (match(Op1, m_Zero()))
return UndefValue::get(Op1->getType());
// undef / X -> 0
if (match(Op0, m_Undef()))
return Constant::getNullValue(Op0->getType());

View File

@ -160,3 +160,17 @@ define <4 x i8> @test19(<4 x i8> %a) {
%b = shl <4 x i8> %a, <i8 8, i8 9, i8 undef, i8 -1>
ret <4 x i8> %b
}
; CHECK-LABEL: @test20
; CHECK: ret i32 undef
define i32 @test20(i32 %a) {
%b = udiv i32 %a, 0
ret i32 %b
}
; CHECK-LABEL: @test21
; CHECK: ret i32 undef
define i32 @test21(i32 %a) {
%b = sdiv i32 %a, 0
ret i32 %b
}