[LLVMbugs] [Bug 1193] NEW: incomplete optimization

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Fri Feb 9 18:45:09 PST 2007


           Summary: incomplete optimization
           Product: libraries
           Version: 1.8
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: wenwenti at hotmail.com

I find a problem in my progrom with bit-accurate types. The C program is as follows.

typedef unsigned int __attribute__((bitwidth(11))) uint11;
void test_add_sub(uint11 a, uint11 b, uint11* r1, uint11* r2)
    *r1 = a + b;
    *r2 = a -b;
    return ;

The generated llvm code looks like this
; ModuleID = '<stdin>'
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"

implementation   ; Functions:

define void @test_add_sub(i11 sext  %a, i11 sext  %b, i11* %r1, i11* %r2) {
        %tmp45 = add i11 %b, %a         ; <i11> [#uses=1]
        store i11 %tmp45, i11* %r1
        %tmp78 = sext i11 %a to i16             ; <i16> [#uses=1]
        %tmp910 = sext i11 %b to i16            ; <i16> [#uses=1]
        %tmp11 = sub i16 %tmp78, %tmp910                ; <i16> [#uses=1]
        %tmp1112 = trunc i16 %tmp11 to i11              ; <i11> [#uses=1]
        store i11 %tmp1112, i11* %r2
        ret void

The add instruction using 11-bit is fine. However, the sub instruction uses
16-bit. Then the value is truncated back to 11-bit. The optimization to the add
instruction should also be applied to sub instruction. I don't know why it does not.


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

More information about the llvm-bugs mailing list