[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp LICM.cpp SCCP.cpp ScalarReplAggregates.cpp

Chris Lattner clattner at apple.com
Thu Feb 1 22:01:51 PST 2007


> diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.619  
> llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.620
> --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.619	Thu  
> Feb  1 16:30:07 2007
> +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Feb  1  
> 20:16:22 2007

I already committed some code.


> @@ -1197,8 +1200,8 @@
>      // the shift amount is >= the size of the datatype, which is  
> undefined.
>      if (DemandedMask == 1) {
>        // Perform the logical shift right.
> -      Value *NewVal = new ShiftInst(Instruction::LShr, I- 
> >getOperand(0),
> -                                    I->getOperand(1), I->getName());
> +      Value *NewVal = BinaryOperator::create(Instruction::LShr,

BinaryOperator::createLShr please, likewise elsewhere in many places  
in the file.

>
> @@ -4599,13 +4601,18 @@
>            // could exist), turn it into (X & (C2 << C1)) != (C3 <<  
> C1).  This
>            // happens a LOT in code produced by the C front-end,  
> for bitfield
>            // access.
> -          ShiftInst *Shift = dyn_cast<ShiftInst>(LHSI->getOperand 
> (0));
> +          BinaryOperator *Shift = dyn_cast<BinaryOperator>(LHSI- 
> >getOperand(0));
> +          if (Shift && !Shift->isShift())
> +            Shift = 0;
>
>            // Check to see if there is a noop-cast between the  
> shift and the and.
>            if (!Shift) {
>              if (CastInst *CI = dyn_cast<CastInst>(LHSI->getOperand 
> (0)))
> -              if (CI->getOpcode() == Instruction::BitCast)
> -                Shift = dyn_cast<ShiftInst>(CI->getOperand(0));
> +              if (CI->getOpcode() == Instruction::BitCast) {
> +                Shift = dyn_cast<BinaryOperator>(CI->getOperand(0));
> +                if (Shift && !Shift->isShift())
> +                  Shift = 0;
> +              }
>            }

This code can be eliminated.  Noop casts are no longer an issue now  
that int->uint casts don't exist.

> @@ -5489,13 +5508,12 @@
>
>            // Turn (Y + ((X >> C) & CC)) << C  ->  ((X & (CC << C))  
> + (Y << C))
>            if (isLeftShift && Op0BO->getOperand(1)->hasOneUse() &&
> -              match(Op0BO->getOperand(1),
> -                    m_And(m_Shr(m_Value(V1), m_Value(V2)),
> -                          m_ConstantInt(CC))) && V2 == Op1 &&
> +              match(Op0BO->getOperand(1), m_And(m_Shr(m_Value(V1),  
> m_Value(V2)),
> +                    m_ConstantInt(CC))) && V2 == Op1 &&

Please fix the indentation here.

> @@ -5595,15 +5613,15 @@
>    }
>
>    // Find out if this is a shift of a shift by a constant.
> -  ShiftInst *ShiftOp = 0;
> -  if (ShiftInst *Op0SI = dyn_cast<ShiftInst>(Op0))
> -    ShiftOp = Op0SI;
> -  else if (BitCastInst *CI = dyn_cast<BitCastInst>(Op0)) {
> -    // If this is a noop-integer cast of a shift instruction, use  
> the shift.
> -    if (isa<ShiftInst>(CI->getOperand(0))) {
> -      ShiftOp = cast<ShiftInst>(CI->getOperand(0));
> -    }
> -  }
> +  BinaryOperator *ShiftOp = dyn_cast<BinaryOperator>(Op0);
> +  if (ShiftOp && !ShiftOp->isShift())
> +    ShiftOp = 0;
> +  if (!ShiftOp)
> +    if (BitCastInst *CI = dyn_cast<BitCastInst>(Op0))
> +      // If this is a noop-integer cast of a shift instruction,  
> use the shift.
> +      if (BinaryOperator *SI = dyn_cast<BinaryOperator>(CI- 
> >getOperand(0)))
> +        if (SI->isShift())
> +          ShiftOp = SI;

Likewise, the noop-cast case here should be eliminated.

> @@ -6570,11 +6595,13 @@
>        return BinaryOperator::create(BO->getOpcode(), NewSI, MatchOp);
>    }
>
> -  assert(isa<ShiftInst>(TI) && "Should only have Shift here");
> +  assert(TI->isShift() && "Should only have Shift here");
>    if (MatchIsOpZero)
> -    return new ShiftInst(cast<ShiftInst>(TI)->getOpcode(),  
> MatchOp, NewSI);
> +    return BinaryOperator::create(Instruction::BinaryOps(TI- 
> >getOpcode()),
> +                                  MatchOp, NewSI);
>    else
> -    return new ShiftInst(cast<ShiftInst>(TI)->getOpcode(), NewSI,  
> MatchOp);
> +    return BinaryOperator::create(Instruction::BinaryOps(TI- 
> >getOpcode()),
> +                                  NewSI, MatchOp);
>  }

This code is dead, please remove.


Nice series of patches Reid, this is a great change.

-Chris



More information about the llvm-commits mailing list