<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 22, 2008, at 2:10 AM, humeafo wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"> <div><font face="Verdana"><font size="2"> <div>I am a newbie to LLVM, so I have to say sorry if I asked the question in the wrong place.</div> <div>In some cases when I generate LLVM IR from machine assembly(with limited type information) I have to convert the pointers to I32, after the standard mem2reg pass there still are things like:</div> <div> </div> <div>inttoptr i32 %1 to i8*</div> <div> </div> <div>While in fact this can be replaced by the I8* operations, because the I8* can be unsigned compared, and get rid of the redundant Instrs, Is there any pass</div> <div>can do this, or is there any tricks to avoid these redundant conversions while retain the meaning of the program?</div></font></font></div></blockquote><div><br class="webkit-block-placeholder"></div><div>Sure, the instcombine pass will do this.  Make sure to add the correct target data string though.  For example, if I add the datalayout string for x86-32 darwin:</div><div><br class="webkit-block-placeholder"></div><div><div>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-f80:128:128"</div><div><br class="webkit-block-placeholder"></div><div>Instcombine produces:</div><div><br class="webkit-block-placeholder"></div><div><div>define i8* @tag_on(i8* %ptr, i8* %end, i8 %tag) {</div><div>Entry:</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>icmp ugt i8* %end, %ptr<span class="Apple-tab-span" style="white-space:pre">             </span>; <i1>:0 [#uses=1]</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>br i1 %0, label %B1, label %B2</div><div><br class="webkit-block-placeholder"></div><div>B1:<span class="Apple-tab-span" style="white-space:pre">                </span>; preds = %Entry</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>store i8 1, i8* %ptr</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>%ctg2 = getelementptr i8* %ptr, i32 1<span class="Apple-tab-span" style="white-space:pre">               </span>; <i8*> [#uses=1]</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>br label %B2</div><div><br class="webkit-block-placeholder"></div><div>B2:<span class="Apple-tab-span" style="white-space:pre">          </span>; preds = %B1, %Entry</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>%eax.0.in = phi i8* [ %ctg2, %B1 ], [ %ptr, %Entry ]<span class="Apple-tab-span" style="white-space:pre">                </span>; <i8*> [#uses=4]</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>icmp ult i8* %eax.0.in, %end<span class="Apple-tab-span" style="white-space:pre">                </span>; <i1>:1 [#uses=1]</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>br i1 %1, label %B3, label %exit</div><div><br class="webkit-block-placeholder"></div><div>B3:<span class="Apple-tab-span" style="white-space:pre">              </span>; preds = %B2</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>store i8 1, i8* %eax.0.in</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>%ctg21 = getelementptr i8* %eax.0.in, i32 1<span class="Apple-tab-span" style="white-space:pre">         </span>; <i8*> [#uses=1]</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>br label %exit</div><div><br class="webkit-block-placeholder"></div><div>exit:<span class="Apple-tab-span" style="white-space:pre">              </span>; preds = %B3, %B2</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>%eax.1.in = phi i8* [ %ctg21, %B3 ], [ %eax.0.in, %B2 ]<span class="Apple-tab-span" style="white-space:pre">             </span>; <i8*> [#uses=1]</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>ret i8* %eax.1.in</div><div>}</div><div><br class="webkit-block-placeholder"></div><div>Note that it eliminated all the ptrtoint casts (in this case) and infered some getelementptrs.</div><div><br class="webkit-block-placeholder"></div><div>I'm sending this to the llvmdev list, which is a better place for high-level questions than llvm-commits.</div><div><br class="webkit-block-placeholder"></div><div>-Chris</div></div></div><br><blockquote type="cite"><div><font face="Verdana"><font size="2"> <div><br>define i8* @tag_on(i8* %ptr, i8* %end, i8 %tag) {<br>Entry:<br>        ptrtoint i8* %end to i32                ; <i32>:0 [#uses=2]<br>        ptrtoint i8* %ptr to i32                ; <i32>:1 [#uses=4]<br>        icmp ugt i32 %0, %1             ; <i1>:2 [#uses=1]<br>        br i1 %2, label %B1, label %B2</div> <div> </div> <div>B1:             ; preds = %Entry<br>        inttoptr i32 %1 to i8*          ; <i8*>:3 [#uses=1]<br>        store i8 1, i8* %3<br>        add i32 %1, 1           ; <i32>:4 [#uses=1]<br>        br label %B2</div> <div> </div> <div>B2:             ; preds = %Entry, %B1<br>        %eax.0 = phi i32 [ %4, %B1 ], [ %1, %Entry ]            ; <i32> [#uses=4]<br>        icmp ugt i32 %0, %eax.0         ; <i1>:5 [#uses=1]<br>        br i1 %5, label %B3, label %exit</div> <div> </div> <div>B3:             ; preds = %B2<br>        inttoptr i32 %eax.0 to i8*              ; <i8*>:6 [#uses=1]<br>        store i8 1, i8* %6<br>        add i32 %eax.0, 1               ; <i32>:7 [#uses=1]<br>        br label %exit</div> <div> </div> </font><div><font size="2">exit:           ; preds = %B2, %B3<br>        %eax.1 = phi i32 [ %7, %B3 ], [ %eax.0, %B2 ]           ; <i32> [#uses=1]<br>        inttoptr i32 %eax.1 to i8*              ; <i8*>:8 [#uses=1]<br>        ret i8* %8<br>}</font></div> <div><font size="2"></font> </div> <div align="left"><font size="2"> <hr style="WIDTH: 122px; HEIGHT: 2px" size="2"> </font></div> <div><font color="#c0c0c0"><font size="2">humeafo</font></font></div><font color="#c0c0c0"> </font><div><font color="#c0c0c0"><font size="2">2008-01-22</font></font></div></font></div> _______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></div><br></body></html>