mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 01:43:57 +00:00
[InstSimplify] Optimize away udivs in the presence of range metadata
We know that udiv %V, C can be optimized away to 0 if %V is ult C. llvm-svn: 291296
This commit is contained in:
parent
8c87177d0b
commit
93fad2f404
@ -1106,6 +1106,16 @@ static Value *SimplifyUDivInst(Value *Op0, Value *Op1, const Query &Q,
|
||||
if (Value *V = SimplifyDiv(Instruction::UDiv, Op0, Op1, Q, MaxRecurse))
|
||||
return V;
|
||||
|
||||
// udiv %V, C -> 0 if %V < C
|
||||
if (MaxRecurse) {
|
||||
if (Constant *C = dyn_cast_or_null<Constant>(SimplifyICmpInst(
|
||||
ICmpInst::ICMP_ULT, Op0, Op1, Q, MaxRecurse - 1))) {
|
||||
if (C->isAllOnesValue()) {
|
||||
return Constant::getNullValue(Op0->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
15
test/Transforms/InstSimplify/div.ll
Normal file
15
test/Transforms/InstSimplify/div.ll
Normal file
@ -0,0 +1,15 @@
|
||||
; RUN: opt < %s -instsimplify -S | FileCheck %s
|
||||
|
||||
declare i32 @external()
|
||||
|
||||
define i32 @div1() {
|
||||
; CHECK-LABEL: @div1(
|
||||
; CHECK: [[CALL:%.*]] = call i32 @external(), !range !0
|
||||
; CHECK-NEXT: ret i32 0
|
||||
;
|
||||
%call = call i32 @external(), !range !0
|
||||
%urem = udiv i32 %call, 3
|
||||
ret i32 %urem
|
||||
}
|
||||
|
||||
!0 = !{i32 0, i32 3}
|
Loading…
x
Reference in New Issue
Block a user