<html>
    <head>
      <base href="http://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 --- - Recursive function inline problems"
   href="http://llvm.org/bugs/show_bug.cgi?id=18459">18459</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Recursive function inline problems
          </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>Linux
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>css20@mail.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11863" name="attach_11863" title="testcase">attachment 11863</a> <a href="attachment.cgi?id=11863&action=edit" title="testcase">[details]</a></span>
testcase

Follow this steps using attachment puzzle.ll:

llvm-as -f puzzle.ll
llc puzzle.bc
gcc puzzle.s -o puzzle
./puzzle

Found duplicate: 256943
Found duplicate: 106186
Found duplicate: 465226
Found duplicate: 112763
Found duplicate: 406647

Then try optimize bitcode:
opt -inline puzzle.bc -o puzzle.opt.bc
llc puzzle.opt.bc
gcc puzzle.opt.s -o puzzle.opt
./puzzle.opt

Found duplicate: 491574
Found duplicate: 480454
Found duplicate: 447135
Found duplicate: 255009
Found duplicate: 419126


Strange optimization.. ok, try bugpoint

bugpoint --safe-run-llc --run-llc puzzle.bc -inline

...

*** The following function is being miscompiled:  .shuffle.createRandomArray
Outputting reduced bitcode files which expose the problem:
  Non-optimized portion: Emitted bitcode to 'bugpoint-tonotoptimize.bc'
  Portion that is input to optimizer: Emitted bitcode to
'bugpoint-tooptimize.bc'

*** You can reproduce the problem with: opt bugpoint-tooptimize.bc -inline



bugpoint-tooptimize.bc disasseble fragment:

define i32* @.shuffle.createRandomArray(i32* %items, i32 %functionID, i32
%len.size) {
combEntry:
  %"collect alloca point17" = bitcast i32 0 to i32
  %"collect alloca point16" = bitcast i32 0 to i32
  %"collect alloca point15" = bitcast i32 0 to i32
  %"collect alloca point14" = bitcast i32 0 to i32
  %"collect alloca point13" = bitcast i32 0 to i32
  %"collect alloca point12" = bitcast i32 0 to i32
  %"collect alloca point11" = bitcast i32 0 to i32
  %"collect alloca point" = bitcast i32 0 to i32
  switch i32 %functionID, label %codeRepl3 [
    i32 38, label %codeRepl2
    i32 39, label %entryfcomb1
  ]

codeRepl2:                                        ; preds = %combEntry
  call void @.shuffle.createRandomArray_combEntry.entryfcomb_crit_edge1()
  br label %entryfcomb

codeRepl3:                                        ; preds = %combEntry
  call void @.shuffle.createRandomArray_combEntry.entryfcomb_crit_edge()
  br label %entryfcomb

entryfcomb:                                       ; preds = %codeRepl3,
%codeRepl2
  %subfcomb = sub nsw i32 %len.size, 1
  %convfcomb = sext i32 %subfcomb to i64
  br label %codeRepl4

codeRepl4:                                        ; preds = %entryfcomb
  call void @.shuffle.createRandomArray_codeRepl(i64 %convfcomb, i32* %items)
  br label %codeRepl

codeRepl:                                         ; preds = %codeRepl4
  call void @.shuffle.createRandomArray_for.endfcomb()
  br label %for.endfcomb.ret

for.endfcomb.ret:                                 ; preds = %codeRepl
  ret i32* null

entryfcomb1:                                      ; preds = %combEntry
  %addfcomb3 = add nsw i32 %len.size, 1
  %convfcomb4 = sext i32 %addfcomb3 to i64
  %mulfcomb5 = mul i64 %convfcomb4, 4
  %callfcomb = call i8* @malloc(i64 %mulfcomb5)
  %0 = bitcast i8* %callfcomb to i32*
  br label %codeRepl5

codeRepl5:                                        ; preds = %entryfcomb1
  call void @.shuffle.createRandomArray_codeRepl1(i32 %addfcomb3, i32* %0)
  br label %for.endfcomb10

for.endfcomb10:                                   ; preds = %codeRepl5
  %call24fcomb = call i32 @.rand.srand.randInt(i32 1, i32 %len.size, i32 38)
  %arrayidx3fcomb = getelementptr inbounds i32* %0, i64 0
  store i32 %call24fcomb, i32* %arrayidx3fcomb, align 4, !tbaa !1
  %1 = call i32* @.shuffle.createRandomArray(i32* %0, i32 38, i32 %addfcomb3)
  ret i32* %0
}


look basic block for.endfcomb10, it contains recursive call. Now we can see
content of "for.endfcomb10" basic block after optimization (opt -inline):

for.endfcomb10:                                   ; preds = %codeRepl5
  %call24fcomb = call i32 @.rand.srand.randInt(i32 1, i32 %len.size, i32 8)
  %arrayidx3fcomb = getelementptr inbounds i32* %0, i64 0
  store i32 %call24fcomb, i32* %arrayidx3fcomb, align 4, !tbaa !1

  ; here was recursive call
  call void @.shuffle.createRandomArray_combEntry.entryfcomb_crit_edge1()
  %convfcomb.i = sext i32 %addfcomb3 to i64
  call void @.shuffle.createRandomArray_codeRepl(i64 %convfcomb.i, i32* %0)
  call void @.shuffle.createRandomArray_for.endfcomb()
  ret i32* %0

If we try walk manually to call @.shuffle.createRandomArray(i32* %0, i32 38,
i32 %addfcomb3), we must pass this instructions:

call void @.shuffle.createRandomArray_combEntry.entryfcomb_crit_edge1()
%subfcomb = sub nsw i32 %addfcomb3, 1  ; <--- WHERE IS IT???
%convfcomb = sext i32 %subfcomb to i64
call void @.shuffle.createRandomArray_codeRepl(i64 %convfcomb, i32* %items)
call void @.shuffle.createRandomArray_for.endfcomb()

Instruction "%subfcomb = sub nsw i32 %addfcomb3, 1" not exists in listing after
optimization, "-inline" pass loses it?</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>