llvm.org GIT mirror llvm / 597f295
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 Benjamin Kramer 7 years ago
2 changed file(s) with 22 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
14451445 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
14461446 APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
14471447
1448 nc = allOnes - (-d).urem(d);
1448 nc = allOnes - (allOnes - d).urem(d);
14491449 p = d.getBitWidth() - 1; // initialize p
14501450 q1 = signedMin.udiv(nc); // initialize q1 = 2p/nc
14511451 r1 = signedMin - q1*nc; // initialize r1 = rem(2p,nc)
7070 ; CHECK-NOT: shrl
7171 ; CHECK: ret
7272 }
73
74 ; PR13326
75 define i8 @test8(i8 %x) nounwind {
76 %div = udiv i8 %x, 78
77 ret i8 %div
78 ; CHECK: test8:
79 ; CHECK: shrb %
80 ; CHECK: imull $211
81 ; CHECK: shrl $13
82 ; CHECK: ret
83 }
84
85 define i8 @test9(i8 %x) nounwind {
86 %div = udiv i8 %x, 116
87 ret i8 %div
88 ; CHECK: test9:
89 ; CHECK: shrb $2
90 ; CHECK: imull $71
91 ; CHECK: shrl $11
92 ; CHECK: ret
93 }