mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
PR13326: Fix a subtle edge case in the udiv -> magic multiply generator.
This caused 6 of 65k possible 8 bit udivs to be wrong. llvm-svn: 160058
This commit is contained in:
parent
0f2aecdfe8
commit
e4bd0cdfa8
@ -1446,7 +1446,7 @@ APInt::mu APInt::magicu(unsigned LeadingZeros) const {
|
||||
APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
|
||||
APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
|
||||
|
||||
nc = allOnes - (-d).urem(d);
|
||||
nc = allOnes - (allOnes - d).urem(d);
|
||||
p = d.getBitWidth() - 1; // initialize p
|
||||
q1 = signedMin.udiv(nc); // initialize q1 = 2p/nc
|
||||
r1 = signedMin - q1*nc; // initialize r1 = rem(2p,nc)
|
||||
|
@ -71,3 +71,24 @@ define i32 @test7(i32 %x) nounwind {
|
||||
; CHECK-NOT: shrl
|
||||
; CHECK: ret
|
||||
}
|
||||
|
||||
; PR13326
|
||||
define i8 @test8(i8 %x) nounwind {
|
||||
%div = udiv i8 %x, 78
|
||||
ret i8 %div
|
||||
; CHECK: test8:
|
||||
; CHECK: shrb %
|
||||
; CHECK: imull $211
|
||||
; CHECK: shrl $13
|
||||
; CHECK: ret
|
||||
}
|
||||
|
||||
define i8 @test9(i8 %x) nounwind {
|
||||
%div = udiv i8 %x, 116
|
||||
ret i8 %div
|
||||
; CHECK: test9:
|
||||
; CHECK: shrb $2
|
||||
; CHECK: imull $71
|
||||
; CHECK: shrl $11
|
||||
; CHECK: ret
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user