<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56178>56178</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang 13.0.1 miscompiles SVE VLA build of clang 14
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DavidSpickett
      </td>
    </tr>
</table>

<pre>
    I'm aware the 13 branch is done with, I'm just filing this for record keeping in case others hit it.

Since https://lab.llvm.org/buildbot/#/builders/198/builds/998 it appears that the 13.0.1 we use as the host compiler is miscompiling clang in the 1st stage leading to an assertion failure when building stage 2.

This only happens with a build that is targeting SVE VLA (vector length agnostic) codegen. On other machines or without that option (specifically the slp-vectorize seems to be the key) there is no issue. The reproducer does not fail on machines that did not build stage 1 with SVE code, which is what says to me this is an issue with the host compiler.

`main` is `cedfd7a2e536d2ff6da44e89a024baa402dc3e58` for that buildbot run but that particular change is not the cause of the issue. This is just the first time the build got to the failure point. I think some code shuffling elsewhere uncovered the bug.

```
FAILED: tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/IntegerRelation.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++  -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=1 -DMLIR_ROCM_CONVERSIONS_ENABLED=1 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/mlir/lib/Analysis/Presburger -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/mlir/lib/Analysis/Presburger -Iinclude -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/mlir/include -Itools/mlir/include -mcpu=a64fx -mllvm -scalable-vectorization=preferred -mllvm -treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=mismatched-tags -Werror=global-constructors -O3 -DNDEBUG    -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/IntegerRelation.cpp.o -MF tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/IntegerRelation.cpp.o.d -o tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/IntegerRelation.cpp.o -c /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
clang++: /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/lib/CodeGen/MachineRegisterInfo.cpp:400: llvm::MachineInstr *llvm::MachineRegisterInfo::getVRegDef(llvm::Register) const: Assertion `(I.atEnd() || std::next(I) == def_instr_end()) && "getVRegDef assumes a single definition or no definition"' failed.
```

This is fixed in 14.0.5 but I do not know which change fixed it.

If anyone else hits this we can find that out. In the meantime, we (Linaro) are going to move to clang 14 for at least this bot.

creduced reproducer: [sve repro.zip](https://github.com/llvm/llvm-project/files/8967811/sve.repro.zip)
(the reproducer that causes the assert failure when using the clang 14 built in stage 1, not the reproducer that triggers the bug in the host clang 13, which I do not have at this time)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org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