<div>Hi Chris,<br><br> </div>
<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">> The condition "IterationCount->getType() != LargestType" doesn't<br>> mean the IterationCount->getType's bitwidth < LargestType's
<br>> so, sometimes, (like in this testcase), it need a trunc not ext.<br>> This patch is to fix it.<br><br>Ah, I see.  Thank you for checking in the testcase.   The reason this<br>looked fishy to me is that the code attempts to insert the IV as the
<br>largest type, but that it could then need a zero extend.   Doesn't<br>this mean the zero extend case (which I know you didn't put in<br>there :) is really dead?  If so, please remove it and switch back to<br>a simple:
<br><br>    if (IterationCount->getType() != LargestType)<br>      IterationCount = SCEVTruncateExpr::get(IterationCount,<br>LargestType);</blockquote>
<div> </div>
<div>No, it's incorrect. That will fail llvm/test/Transforms/IndVarSimplify/exit_value_tests.llx ( which got an assertion)</div>
<div>i think we should keep the extend code.</div>
<div> </div>
<div> </div>
<div>Sheng.</div>
<div> </div>
<div> </div>
<div> </div><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Thanks!  If this doesn't make any sense, please feel free to ask for<br>clarification :)<br><br>-Chris
<br><br>> Sheng<br>><br>><br>><br>>   DOUT << "INDVARS: New CanIV: " << *IndVar;<br>>><br>>>    if (!isa<SCEVCouldNotCompute>(IterationCount)) {<br>>> -    if (IterationCount->getType() != LargestType)
<br>>> +    if (IterationCount->getType()->getPrimitiveSizeInBits() <<br>>> +        LargestType->getPrimitiveSizeInBits())<br>>>        IterationCount = SCEVZeroExtendExpr::get(IterationCount,
<br>>> LargestType);<br>>> +    else if (IterationCount->getType() != LargestType)<br>>> +      IterationCount = SCEVTruncateExpr::get(IterationCount,<br>>> LargestType);<br>>>      if (Instruction *DI = LinearFunctionTestReplace(L,
<br>>> IterationCount,Rewriter))<br>>>        DeadInsts.insert(DI);<br>>>    }<br>><br>><br>> <testcase.bc><br>> ; ModuleID = 'testcase.bc'<br>> target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-
<br>> i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"<br>> target triple = "i686-pc-linux-gnu"<br>><br>> define i32 @testcase(i5 zext  %k) {<br>> entry:<br>>       br label %bb2
<br>><br>> bb:           ; preds = %bb2<br>>       %tmp1 = add i32 %tmp2, %result          ; <i32> [#uses=1]<br>>       %indvar_next1 = add i5 %k_0, 1          ; <i5> [#uses=1]<br>>       br label %bb2
<br>><br>> bb2:          ; preds = %bb, %entry<br>>       %k_0 = phi i5 [ 0, %entry ], [ %indvar_next1, %bb ]             ; <i5> [#uses=2]<br>>       %result = phi i32 [ 0, %entry ], [ %tmp1, %bb ]         ; <i32> [#uses=2]
<br>>       %tmp2 = zext i5 %k_0 to i32             ; <i32> [#uses=1]<br>>       %exitcond = icmp eq i32 %tmp2, 16               ; <i1> [#uses=1]<br>>       br i1 %exitcond, label %bb3, label %bb<br>>
<br>> bb3:          ; preds = %bb2<br>>       ret i32 %result<br>> }<br><br></blockquote></div><br>