<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - [SelectionDAG] Seemingly incorrect updating of chains in UpdateChains()"
   href="https://bugs.llvm.org/show_bug.cgi?id=36164">36164</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SelectionDAG] Seemingly incorrect updating of chains in UpdateChains()
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>paulsson@linux.vnet.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19779" name="attach_19779" title="reduced testcase">attachment 19779</a> <a href="attachment.cgi?id=19779&action=edit" title="reduced testcase">[details]</a></span>
reduced testcase

Incorrect updating of DAG chains during Select(), which leads to a node having
a deleted node as chain input.

Run with

llc -mtriple=s390x-linux-gnu -mcpu=z13 -disable-basicaa ./tc_DAG_badchain.ll

llc: lib/CodeGen/SelectionDAG/InstrEmitter.cpp:802: void
llvm::InstrEmitter::EmitMachineNode(llvm::SDNode*, bool, bool,
llvm::DenseMap<llvm::SDValue, unsigned int>&): Assertion `NumMIOperands >=
II.getNumOperands() && NumMIOperands <= II.getNumOperands()\
 + II.getNumImplicitDefs() + NumImpUses && "#operands for dag node doesn't
match .td file!"' failed.
....

Reduced DAG just before t50 gets selected:

  t378: i64,ch = load<LD8[@g_938](tbaa=<0x51f0978>)(dereferenceable)> t0, t402,
undef:i64
                              t313: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_8

  t516: ch = TokenFactor t391:1, t513, t378:1

    t520: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t517, t398, undef:i64
  t521: ch = TokenFactor t516, t520:1
    t518: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t517, Constant:i32<3>, t400,
undef:i64
  t519: ch = TokenFactor t516, t518

  t482: ch = TokenFactor t519, t521
  t478: ch = TokenFactor t521, t519

  t524: i32 = TargetConstant<1>
          t49: i64 = add t378, Constant:i64<24>
        t50: ch = store<ST8[@g_938](tbaa=<0x51f0978>)> t482, t49, t402,
undef:i64

        t475: i32,ch = LRL<Mem:Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> TargetGlobalAddress:i64<%0* @g_832> 0,
t478


The DAG has many (volatile) memory accesses with multiple token factors (see
below for full DAG)

The t378 load has one (value) use which is the t49 add which is then stored by
t50.

The t50 store gets morphed (with load and add folded into it) to 't50: i32,ch =
AGSI...', which is an addition of immediate to memory. This seems ok regarding
the chains, but I'm not 100% sure...

The problem then is with t475, which was chained via t478 eventually up to
t378. It does not seem to get the chain properly updated: After void
SelectionDAGISel::UpdateChains(), it becomes

        t475: i32,ch = LRL<Mem:Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> TargetGlobalAddress:i64<%0* @g_832> 0,
<<Deleted Node!>>:ch

This later leads to an incorrect operand during instruction emission and the
assert triggers for t475.

Complete DAG just before t50 gets selected:

CurDAG->dump() = SelectionDAG has 71 nodes:
  t0: ch = EntryToken
  t398: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<%0* @g_832> 0
  t400: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i32* @g_69> 0
  t402: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i64* @g_938> 0
  t378: i64,ch = load<LD8[@g_938](tbaa=<0x51f0978>)(dereferenceable)> t0, t402,
undef:i64
                              t313: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t0, t398, undef:i64
                            t315: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t313:1, t398, undef:i64
                          t318: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t315:1, t398, undef:i64
                        t321: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t318:1, t398, undef:i64
                      t324: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t321:1, t398, undef:i64
                    t327: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t324:1, t398, undef:i64
                  t330: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t327:1, t398, undef:i64
                t333: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t330:1, t398, undef:i64
              t336: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t333:1, t398, undef:i64
            t339: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t336:1, t398, undef:i64
          t342: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t339:1, t398, undef:i64
        t345: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t342:1, t398, undef:i64
      t348: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t345:1, t398, undef:i64
    t351: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t348:1, t398, undef:i64
  t354: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t351:1, t398, undef:i64
  t358: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t354:1, t398, undef:i64
  t361: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t358:1, t398, undef:i64
  t364: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t361:1, t398, undef:i64
  t387: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t364:1, t398, undef:i64
  t391: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t387:1, t398, undef:i64
                        t404: i64 = SystemZISD::PCREL_WRAPPER
TargetGlobalAddress:i64<i32* @g_73> 0
                      t5: ch = store<ST4[@g_73](tbaa=<0x51f5db8>)> t0,
Constant:i32<1>, t404, undef:i64
                      t381: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t0,
Constant:i32<1>, t400, undef:i64
                    t522: ch = TokenFactor t354:1, t5, t381
                  t493: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t522,
Constant:i32<2>, t400, undef:i64
                t497: ch = TokenFactor t358:1, t493
              t498: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t497,
Constant:i32<3>, t400, undef:i64
            t502: ch = TokenFactor t361:1, t498
          t503: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t502, Constant:i32<0>,
t400, undef:i64
        t507: ch = TokenFactor t364:1, t503
      t508: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t507, Constant:i32<1>,
t400, undef:i64
    t512: ch = TokenFactor t387:1, t508
  t513: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t512, Constant:i32<2>, t400,
undef:i64
  t517: ch = TokenFactor t391:1, t513
  t516: ch = TokenFactor t391:1, t513, t378:1
    t520: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t517, t398, undef:i64
  t521: ch = TokenFactor t516, t520:1
    t518: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t517, Constant:i32<3>, t400,
undef:i64
  t519: ch = TokenFactor t516, t518
  t482: ch = TokenFactor t519, t521
  t478: ch = TokenFactor t521, t519
  t524: i32 = TargetConstant<1>
      t396: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i1* @g_11>
0
          t49: i64 = add t378, Constant:i64<24>
        t50: ch = store<ST8[@g_938](tbaa=<0x51f0978>)> t482, t49, t402,
undef:i64
          t480: ch = STRL<Mem:ST4[@g_69](tbaa=<0x51f5db8>)> Constant:i32<4>,
TargetGlobalAddress:i64<i32* @g_69> 0, t478
        t481: ch = TokenFactor t482, t480
        t475: i32,ch = LRL<Mem:Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> TargetGlobalAddress:i64<%0* @g_832> 0,
t478
      t477: ch = TokenFactor t50, t481, t475:1
    t394: ch = MVI<Mem:ST1[@g_11](align=4)> t396, TargetConstant:i64<0>,
TargetConstant:i64<1>, t477
  t58: ch = J BasicBlock:ch< 0x524f328>, t394


Complete DAG just after t50 was selected:

CurDAG->dump() = SelectionDAG has 65 nodes:
  t0: ch = EntryToken
  t398: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<%0* @g_832> 0
  t400: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i32* @g_69> 0
                              t313: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t0, t398, undef:i64
                            t315: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t313:1, t398, undef:i64
                          t318: i32,ch = load<Volatile LD4[getelementptr
inbounds (%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t315:1, t398, undef:i64
                        t321: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t318:1, t398, undef:i64
                      t324: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t321:1, t398, undef:i64
                    t327: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t324:1, t398, undef:i64
                  t330: i32,ch = load<Volatile LD4[getelementptr inbounds
(%"type 0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t327:1, t398, undef:i64
                t333: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t330:1, t398, undef:i64
              t336: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t333:1, t398, undef:i64
            t339: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t336:1, t398, undef:i64
          t342: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t339:1, t398, undef:i64
        t345: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t342:1, t398, undef:i64
      t348: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t345:1, t398, undef:i64
    t351: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t348:1, t398, undef:i64
  t354: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t351:1, t398, undef:i64
  t358: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t354:1, t398, undef:i64
  t361: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t358:1, t398, undef:i64
  t364: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t361:1, t398, undef:i64
  t387: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t364:1, t398, undef:i64
  t391: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type 0x51ed1a0",
%"type 0x51ed1a0"* @g_832, i64 0, i32 0)](tbaa=<0x51f14b8>)(dereferenceable)>
t387:1, t398, undef:i64
                        t404: i64 = SystemZISD::PCREL_WRAPPER
TargetGlobalAddress:i64<i32* @g_73> 0
                      t5: ch = store<ST4[@g_73](tbaa=<0x51f5db8>)> t0,
Constant:i32<1>, t404, undef:i64
                      t381: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t0,
Constant:i32<1>, t400, undef:i64
                    t522: ch = TokenFactor t354:1, t5, t381
                  t493: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t522,
Constant:i32<2>, t400, undef:i64
                t497: ch = TokenFactor t358:1, t493
              t498: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t497,
Constant:i32<3>, t400, undef:i64
            t502: ch = TokenFactor t361:1, t498
          t503: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t502, Constant:i32<0>,
t400, undef:i64
        t507: ch = TokenFactor t364:1, t503
      t508: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t507, Constant:i32<1>,
t400, undef:i64
    t512: ch = TokenFactor t387:1, t508
  t513: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t512, Constant:i32<2>, t400,
undef:i64
  t517: ch = TokenFactor t391:1, t513
    t402: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i64* @g_938>
0
      t520: i32,ch = load<Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> t517, t398, undef:i64
      t518: ch = store<ST4[@g_69](tbaa=<0x51f5db8>)> t517, Constant:i32<3>,
t400, undef:i64
    t526: ch = TokenFactor t0, t520:1, t518, t391:1, t513
  t50: i32,ch = AGSI<Mem:ST8[@g_938](tbaa=<0x51f0978>)
LD8[@g_938](tbaa=<0x51f0978>)(dereferenceable)> t402, TargetConstant:i64<0>,
TargetConstant:i64<24>, t526
  t524: i32 = TargetConstant<1>
      t396: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<i1* @g_11>
0
          t480: ch = STRL<Mem:ST4[@g_69](tbaa=<0x51f5db8>)> Constant:i32<4>,
TargetGlobalAddress:i64<i32* @g_69> 0, <<Deleted Node!>>:ch
        t481: ch = TokenFactor t50:1, t480
        t475: i32,ch = LRL<Mem:Volatile LD4[getelementptr inbounds (%"type
0x51ed1a0", %"type 0x51ed1a0"* @g_832, i64 0, i32
0)](tbaa=<0x51f14b8>)(dereferenceable)> TargetGlobalAddress:i64<%0* @g_832> 0,
<<Deleted Node!>>:ch
      t477: ch = TokenFactor t50:1, t481, t475:1
    t394: ch = MVI<Mem:ST1[@g_11](align=4)> t396, TargetConstant:i64<0>,
TargetConstant:i64<1>, t477
  t58: ch = J BasicBlock:ch< 0x524f328>, t394</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>