@@ -469,7 +469,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
469
469
470
470
// Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0), likewise for vector.
471
471
if (DestTy->getScalarSizeInBits () == 1 ) {
472
- Constant *One = ConstantInt::get (Src-> getType () , 1 );
472
+ Constant *One = ConstantInt::get (SrcTy , 1 );
473
473
Src = Builder->CreateAnd (Src, One);
474
474
Value *Zero = Constant::getNullValue (Src->getType ());
475
475
return new ICmpInst (ICmpInst::ICMP_NE, Src, Zero);
@@ -488,14 +488,14 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
488
488
// If the shift amount is larger than the size of A, then the result is
489
489
// known to be zero because all the input bits got shifted out.
490
490
if (Cst->getZExtValue () >= ASize)
491
- return ReplaceInstUsesWith (CI, Constant::getNullValue (CI. getType () ));
491
+ return ReplaceInstUsesWith (CI, Constant::getNullValue (DestTy ));
492
492
493
493
// Since we're doing an lshr and a zero extend, and know that the shift
494
494
// amount is smaller than ASize, it is always safe to do the shift in A's
495
495
// type, then zero extend or truncate to the result.
496
496
Value *Shift = Builder->CreateLShr (A, Cst->getZExtValue ());
497
497
Shift->takeName (Src);
498
- return CastInst::CreateIntegerCast (Shift, CI. getType () , false );
498
+ return CastInst::CreateIntegerCast (Shift, DestTy , false );
499
499
}
500
500
501
501
// Transform trunc(lshr (sext A), Cst) to ashr A, Cst to eliminate type
@@ -520,12 +520,12 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
520
520
521
521
// Transform "trunc (and X, cst)" -> "and (trunc X), cst" so long as the dest
522
522
// type isn't non-native.
523
- if (Src->hasOneUse () && isa<IntegerType>(Src-> getType () ) &&
524
- ShouldChangeType (Src-> getType (), CI. getType () ) &&
523
+ if (Src->hasOneUse () && isa<IntegerType>(SrcTy ) &&
524
+ ShouldChangeType (SrcTy, DestTy ) &&
525
525
match (Src, m_And (m_Value (A), m_ConstantInt (Cst)))) {
526
- Value *NewTrunc = Builder->CreateTrunc (A, CI. getType () , A->getName ()+ " .tr" );
526
+ Value *NewTrunc = Builder->CreateTrunc (A, DestTy , A->getName () + " .tr" );
527
527
return BinaryOperator::CreateAnd (NewTrunc,
528
- ConstantExpr::getTrunc (Cst, CI. getType () ));
528
+ ConstantExpr::getTrunc (Cst, DestTy ));
529
529
}
530
530
531
531
return nullptr ;
0 commit comments