[llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Chris Lattner clattner at apple.com
Tue Jul 3 16:41:50 PDT 2007


<sorry for the delay, just now getting unburied from email>

On Jun 27, 2007, at 7:00 PM, Sheng Zhou wrote:

> Chris,
>
> Attached is the testcase, which will get:
>
> opt: /developer/home2/zsth/llvm-gcc-dev/HEAD/llvm/llvm/lib/VMCore/ 
> Constants.cpp:1559: static llvm::Constant*  
> llvm::ConstantExpr::getZExt(llvm::Constant*, const llvm::Type*):  
> Assertion `C->getType()->getPrimitiveSizeInBits() < Ty- 
> >getPrimitiveSizeInBits()&& "SrcTy must be smaller than DestTy for  
> ZExt!"' failed.
>
> The condition "IterationCount->getType() != LargestType" doesn't  
> mean the IterationCount->getType's bitwidth < LargestType's
> so, sometimes, (like in this testcase), it need a trunc not ext.  
> This patch is to fix it.

Ah, I see.  Thank you for checking in the testcase.   The reason this  
looked fishy to me is that the code attempts to insert the IV as the  
largest type, but that it could then need a zero extend.   Doesn't  
this mean the zero extend case (which I know you didn't put in  
there :) is really dead?  If so, please remove it and switch back to  
a simple:

     if (IterationCount->getType() != LargestType)
       IterationCount = SCEVTruncateExpr::get(IterationCount,  
LargestType);

Thanks!  If this doesn't make any sense, please feel free to ask for  
clarification :)

-Chris

> Sheng
>
>
>
>   DOUT << "INDVARS: New CanIV: " << *IndVar;
>>
>>    if (!isa<SCEVCouldNotCompute>(IterationCount)) {
>> -    if (IterationCount->getType() != LargestType)
>> +    if (IterationCount->getType()->getPrimitiveSizeInBits() <
>> +        LargestType->getPrimitiveSizeInBits())
>>        IterationCount = SCEVZeroExtendExpr::get(IterationCount,   
>> LargestType);
>> +    else if (IterationCount->getType() != LargestType)
>> +      IterationCount = SCEVTruncateExpr::get(IterationCount,   
>> LargestType);
>>      if (Instruction *DI = LinearFunctionTestReplace(L,   
>> IterationCount,Rewriter))
>>        DeadInsts.insert(DI);
>>    }
>
>
> <testcase.bc>
> ; ModuleID = 'testcase.bc'
> target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32- 
> i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
> target triple = "i686-pc-linux-gnu"
>
> define i32 @testcase(i5 zext  %k) {
> entry:
> 	br label %bb2
>
> bb:		; preds = %bb2
> 	%tmp1 = add i32 %tmp2, %result		; <i32> [#uses=1]
> 	%indvar_next1 = add i5 %k_0, 1		; <i5> [#uses=1]
> 	br label %bb2
>
> bb2:		; preds = %bb, %entry
> 	%k_0 = phi i5 [ 0, %entry ], [ %indvar_next1, %bb ]		; <i5> [#uses=2]
> 	%result = phi i32 [ 0, %entry ], [ %tmp1, %bb ]		; <i32> [#uses=2]
> 	%tmp2 = zext i5 %k_0 to i32		; <i32> [#uses=1]
> 	%exitcond = icmp eq i32 %tmp2, 16		; <i1> [#uses=1]
> 	br i1 %exitcond, label %bb3, label %bb
>
> bb3:		; preds = %bb2
> 	ret i32 %result
> }




More information about the llvm-commits mailing list