[llvm-commits] CAST patch: Part #2: .ll/.bc readers + Analysis

Chris Lattner clattner at apple.com
Mon Nov 20 20:12:01 PST 2006


>>    for (Value::use_iterator UI = Op->use_begin(), UE = Op->use_end();
>>         UI != UE; ++UI)
>>      if (CastInst *Other = dyn_cast<CastInst>(*UI))
>> -      // Check that the types are the same, since this code handles
>> casts...
>> -      if (Other->getType() == I.getType() &&
>> +      // Check that the opcode is the same
>> +      if (Other->getOpcode() == Instruction::CastOps(I.getOpcode())
>> &&
>> +          // Check that the destination types are the same
>> +          Other->getType() == I.getType() &&
>> +          // Check that the source types are the same
>> +          CI.getOperand(0)->getType() ==
>> Other->getOperand(0)->getType() &&
>>            // Is it embedded in the same function?  (This could be
>> false if LHS
>>            // is a constant or global!)
>>            Other->getParent()->getParent() == F &&
>>            // Check to see if this new cast is not I.
>>            Other != &I) {
>>
>>
>> There is no need to check this:
>>
>>
>> +          // Check that the source types are the same
>> +          CI.getOperand(0)->getType() ==
>> Other->getOperand(0)->getType() &&
>>
>>
>> Since you know that CI.getOperand(0) == Other->getOperand(0) already.
>
> How do you know this? Other is a User of CI so how can you be certain
> that their operands equivalent?

The code basically goes like this:

given a cast, look at its operand "Op".  Walk all uses of Op (the for  
loop), looking for casts.  If we find one, do stuff.

Since casts only have one operand, you know that the operand of any  
found cast will be Op, aka CI.getOperand(0).

-Chris



More information about the llvm-commits mailing list