[llvm-commits] a question about type conversion propagation and elimination

humeafo humeafo at gmail.com
Tue Jan 22 02:10:26 PST 2008


I am a newbie to LLVM, so I have to say sorry if I asked the question in the wrong place.
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:

inttoptr i32 %1 to i8*

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
can do this, or is there any tricks to avoid these redundant conversions while retain the meaning of the program?

define i8* @tag_on(i8* %ptr, i8* %end, i8 %tag) {
Entry:
        ptrtoint i8* %end to i32                ; <i32>:0 [#uses=2]
        ptrtoint i8* %ptr to i32                ; <i32>:1 [#uses=4]
        icmp ugt i32 %0, %1             ; <i1>:2 [#uses=1]
        br i1 %2, label %B1, label %B2

B1:             ; preds = %Entry
        inttoptr i32 %1 to i8*          ; <i8*>:3 [#uses=1]
        store i8 1, i8* %3
        add i32 %1, 1           ; <i32>:4 [#uses=1]
        br label %B2

B2:             ; preds = %Entry, %B1
        %eax.0 = phi i32 [ %4, %B1 ], [ %1, %Entry ]            ; <i32> [#uses=4]
        icmp ugt i32 %0, %eax.0         ; <i1>:5 [#uses=1]
        br i1 %5, label %B3, label %exit

B3:             ; preds = %B2
        inttoptr i32 %eax.0 to i8*              ; <i8*>:6 [#uses=1]
        store i8 1, i8* %6
        add i32 %eax.0, 1               ; <i32>:7 [#uses=1]
        br label %exit

exit:           ; preds = %B2, %B3
        %eax.1 = phi i32 [ %7, %B3 ], [ %eax.0, %B2 ]           ; <i32> [#uses=1]
        inttoptr i32 %eax.1 to i8*              ; <i8*>:8 [#uses=1]
        ret i8* %8
}




humeafo
2008-01-22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20080122/a4e44ebb/attachment.html>


More information about the llvm-commits mailing list