forked from OSchip/llvm-project
Use SimplifyDemandedBits on div instructions.
This folds away silly stuff like (a&255)/1000 -> 0. llvm-svn: 130614
This commit is contained in:
parent
6a50bbd284
commit
57b3df59b9
|
@ -320,6 +320,10 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See if we can fold away this div instruction.
|
||||||
|
if (SimplifyDemandedInstructionBits(I))
|
||||||
|
return &I;
|
||||||
|
|
||||||
// (X - (X rem Y)) / Y -> X / Y; usually originates as ((X / Y) * Y) / Y
|
// (X - (X rem Y)) / Y -> X / Y; usually originates as ((X / Y) * Y) / Y
|
||||||
Value *X = 0, *Z = 0;
|
Value *X = 0, *Z = 0;
|
||||||
if (match(Op0, m_Sub(m_Value(X), m_Value(Z)))) { // (X - Z) / Y; Y = Op1
|
if (match(Op0, m_Sub(m_Value(X), m_Value(Z)))) { // (X - Z) / Y; Y = Op1
|
||||||
|
|
|
@ -111,3 +111,10 @@ define i32 @test13(i32 %x) nounwind {
|
||||||
; CHECK-NEXT: ret i32 1
|
; CHECK-NEXT: ret i32 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @test14(i8 %x) nounwind {
|
||||||
|
%zext = zext i8 %x to i32
|
||||||
|
%div = udiv i32 %zext, 257 ; 0
|
||||||
|
ret i32 %div
|
||||||
|
; CHECK: @test14
|
||||||
|
; CHECK-NEXT: ret i32 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue