@@ -32,14 +32,7 @@ using namespace llvm;
32
32
static Value *generateSignedRemainderCode (Value *Dividend, Value *Divisor,
33
33
IRBuilder<> &Builder) {
34
34
unsigned BitWidth = Dividend->getType ()->getIntegerBitWidth ();
35
- ConstantInt *Shift;
36
-
37
- if (BitWidth == 64 ) {
38
- Shift = Builder.getInt64 (63 );
39
- } else {
40
- assert (BitWidth == 32 && " Unexpected bit width" );
41
- Shift = Builder.getInt32 (31 );
42
- }
35
+ ConstantInt *Shift = Builder.getIntN (BitWidth, BitWidth - 1 );
43
36
44
37
// Following instructions are generated for both i32 (shift 31) and
45
38
// i64 (shift 63).
@@ -104,14 +97,7 @@ static Value *generateSignedDivisionCode(Value *Dividend, Value *Divisor,
104
97
// Implementation taken from compiler-rt's __divsi3 and __divdi3
105
98
106
99
unsigned BitWidth = Dividend->getType ()->getIntegerBitWidth ();
107
- ConstantInt *Shift;
108
-
109
- if (BitWidth == 64 ) {
110
- Shift = Builder.getInt64 (63 );
111
- } else {
112
- assert (BitWidth == 32 && " Unexpected bit width" );
113
- Shift = Builder.getInt32 (31 );
114
- }
100
+ ConstantInt *Shift = Builder.getIntN (BitWidth, BitWidth - 1 );
115
101
116
102
// Following instructions are generated for both i32 (shift 31) and
117
103
// i64 (shift 63).
@@ -156,23 +142,10 @@ static Value *generateUnsignedDivisionCode(Value *Dividend, Value *Divisor,
156
142
IntegerType *DivTy = cast<IntegerType>(Dividend->getType ());
157
143
unsigned BitWidth = DivTy->getBitWidth ();
158
144
159
- ConstantInt *Zero;
160
- ConstantInt *One;
161
- ConstantInt *NegOne;
162
- ConstantInt *MSB;
163
-
164
- if (BitWidth == 64 ) {
165
- Zero = Builder.getInt64 (0 );
166
- One = Builder.getInt64 (1 );
167
- NegOne = ConstantInt::getSigned (DivTy, -1 );
168
- MSB = Builder.getInt64 (63 );
169
- } else {
170
- assert (BitWidth == 32 && " Unexpected bit width" );
171
- Zero = Builder.getInt32 (0 );
172
- One = Builder.getInt32 (1 );
173
- NegOne = ConstantInt::getSigned (DivTy, -1 );
174
- MSB = Builder.getInt32 (31 );
175
- }
145
+ ConstantInt *Zero = ConstantInt::get (DivTy, 0 );
146
+ ConstantInt *One = ConstantInt::get (DivTy, 1 );
147
+ ConstantInt *NegOne = ConstantInt::getSigned (DivTy, -1 );
148
+ ConstantInt *MSB = ConstantInt::get (DivTy, BitWidth - 1 );
176
149
177
150
ConstantInt *True = Builder.getTrue ();
178
151
@@ -367,8 +340,7 @@ static Value *generateUnsignedDivisionCode(Value *Dividend, Value *Divisor,
367
340
// / Generate code to calculate the remainder of two integers, replacing Rem with
368
341
// / the generated code. This currently generates code using the udiv expansion,
369
342
// / but future work includes generating more specialized code, e.g. when more
370
- // / information about the operands are known. Implements both 32bit and 64bit
371
- // / scalar division.
343
+ // / information about the operands are known.
372
344
// /
373
345
// / Replace Rem with generated code.
374
346
bool llvm::expandRemainder (BinaryOperator *Rem) {
@@ -379,9 +351,6 @@ bool llvm::expandRemainder(BinaryOperator *Rem) {
379
351
IRBuilder<> Builder (Rem);
380
352
381
353
assert (!Rem->getType ()->isVectorTy () && " Div over vectors not supported" );
382
- assert ((Rem->getType ()->getIntegerBitWidth () == 32 ||
383
- Rem->getType ()->getIntegerBitWidth () == 64 ) &&
384
- " Div of bitwidth other than 32 or 64 not supported" );
385
354
386
355
// First prepare the sign if it's a signed remainder
387
356
if (Rem->getOpcode () == Instruction::SRem) {
@@ -421,12 +390,10 @@ bool llvm::expandRemainder(BinaryOperator *Rem) {
421
390
return true ;
422
391
}
423
392
424
-
425
393
// / Generate code to divide two integers, replacing Div with the generated
426
394
// / code. This currently generates code similarly to compiler-rt's
427
395
// / implementations, but future work includes generating more specialized code
428
- // / when more information about the operands are known. Implements both
429
- // / 32bit and 64bit scalar division.
396
+ // / when more information about the operands are known.
430
397
// /
431
398
// / Replace Div with generated code.
432
399
bool llvm::expandDivision (BinaryOperator *Div) {
@@ -437,9 +404,6 @@ bool llvm::expandDivision(BinaryOperator *Div) {
437
404
IRBuilder<> Builder (Div);
438
405
439
406
assert (!Div->getType ()->isVectorTy () && " Div over vectors not supported" );
440
- assert ((Div->getType ()->getIntegerBitWidth () == 32 ||
441
- Div->getType ()->getIntegerBitWidth () == 64 ) &&
442
- " Div of bitwidth other than 32 or 64 not supported" );
443
407
444
408
// First prepare the sign if it's a signed division
445
409
if (Div->getOpcode () == Instruction::SDiv) {
@@ -540,9 +504,7 @@ bool llvm::expandRemainderUpTo64Bits(BinaryOperator *Rem) {
540
504
541
505
unsigned RemTyBitWidth = RemTy->getIntegerBitWidth ();
542
506
543
- assert (RemTyBitWidth <= 64 && " Div of bitwidth greater than 64 not supported" );
544
-
545
- if (RemTyBitWidth == 64 )
507
+ if (RemTyBitWidth >= 64 )
546
508
return expandRemainder (Rem);
547
509
548
510
// If bitwidth smaller than 64 extend inputs, extend output and proceed
@@ -637,10 +599,7 @@ bool llvm::expandDivisionUpTo64Bits(BinaryOperator *Div) {
637
599
638
600
unsigned DivTyBitWidth = DivTy->getIntegerBitWidth ();
639
601
640
- assert (DivTyBitWidth <= 64 &&
641
- " Div of bitwidth greater than 64 not supported" );
642
-
643
- if (DivTyBitWidth == 64 )
602
+ if (DivTyBitWidth >= 64 )
644
603
return expandDivision (Div);
645
604
646
605
// If bitwidth smaller than 64 extend inputs, extend output and proceed
0 commit comments