forked from OSchip/llvm-project
The sign of an srem instruction is the sign of its dividend (the first
argument), regardless of the divisor. Teach instcombine about this and fix test7 in PR9343! llvm-svn: 126635
This commit is contained in:
parent
8fbf64f420
commit
6b445419b0
llvm
|
@ -1340,6 +1340,16 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Instruction::SRem: {
|
||||
bool TrueIfSigned;
|
||||
if (LHSI->hasOneUse() &&
|
||||
isSignBitCheck(ICI.getPredicate(), RHS, TrueIfSigned)) {
|
||||
// srem has the same sign as its dividend so the divisor is irrelevant.
|
||||
return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0), RHS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Simplify icmp_eq and icmp_ne instructions with integer constant RHS.
|
||||
|
|
|
@ -377,3 +377,13 @@ define i1 @test38(i32 %x, i32 %y, i32 %z) {
|
|||
%c = icmp ugt i32 %lhs, %rhs
|
||||
ret i1 %c
|
||||
}
|
||||
|
||||
; PR9343 #7
|
||||
; CHECK: @test39
|
||||
; CHECK: ret i1 false
|
||||
define i1 @test39(i31 %X, i32 %Y) {
|
||||
%A = zext i31 %X to i32
|
||||
%B = srem i32 %A, %Y
|
||||
%C = icmp slt i32 %B, 0
|
||||
ret i1 %C
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue