mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00: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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160058 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
79137851bf
commit
597f2950d8
@ -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…
Reference in New Issue
Block a user