<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [x86] optimizing for size results in bigger code because of repeated constant"
   href="https://llvm.org/bugs/show_bug.cgi?id=27202">27202</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86] optimizing for size results in bigger code because of repeated constant
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Noticed via <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [InstCombine] missing canonicalization for binop + compare against constant"
   href="show_bug.cgi?id=27105">bug 27105</a>:

define i1 @foo(i32 %i) #0 {
  %and = and i32 %i, 305419896
  %cmp = icmp eq i32 %and, 305419896
  ret i1 %cmp
}

attributes #0 = { "no-frame-pointer-elim"="false" }


$ ./llc maskcmp.ll -filetype=obj ; otool -tv maskcmp.o
...
0000000000000000    andl    $0x12345678, %edi       ## imm = 0x12345678
0000000000000006    cmpl    $0x12345678, %edi       ## imm = 0x12345678
000000000000000c    sete    %al
000000000000000f    retq


Now add an 'optsize' attribute:

define i1 @foo(i32 %i) #0 {
  %and = and i32 %i, 305419896
  %cmp = icmp eq i32 %and, 305419896
  ret i1 %cmp
}

attributes #0 = { optsize "no-frame-pointer-elim"="false" }

$ ./llc maskcmp.ll -filetype=obj ; otool -tv maskcmp.o
...
0000000000000000    andl    $0x12345678, %edi       ## imm = 0x12345678
0000000000000006    movl    $0x12345678, %eax       ## imm = 0x12345678
000000000000000b    cmpl    %eax, %edi
000000000000000d    sete    %al
0000000000000010    retq


We loaded the constant into a register, but we didn't actually use it for the
'and', so the code got bigger rather than smaller.

This is probably related to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [x86] avoid big bad immediates in the instruction stream, part 2: hoist constants"
   href="show_bug.cgi?id=24448">bug 24448</a>, and may be a bug introduced with:
<a href="http://reviews.llvm.org/rL244601">http://reviews.llvm.org/rL244601</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>