Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

ExpandStructRegs: Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed. #176

Closed
TimNN opened this issue Apr 6, 2017 · 3 comments

Comments

@TimNN
Copy link
Contributor

TimNN commented Apr 6, 2017

While working upgrading rust to LLVM 4.0 (rust-lang/rust#40123) I encountered some code being miss-compiled. I investigated this some more recently and found that llc actually produces an assertion when those are enabled.

Compile the following with debug assertions enabled using llc -O0 foo.ll to reproduce:

; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "bugpoint-output-7eb0c3b.bc"
target datalayout = "e-p:32:32-i64:64-v128:32:128-n32-S128"
target triple = "asmjs-unknown-emscripten"

%WrappedArray = type { [2 x i64] }

define fastcc void @_read_wrapped_array(%WrappedArray*) {
entry-block:
  %1 = load %WrappedArray, %WrappedArray* %0, align 8
  %2 = extractvalue %WrappedArray %1, 0
  %.elt = extractvalue [2 x i64] %2, 0
  ret void
}

Output:

llc: .../clang/fastcomp/src/lib/IR/Value.cpp:375: void llvm::Value::doRAUW(llvm::Value*, bool): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
Stack dump:
0.	Program arguments: llc -O0 bugp.1.ll
1.	Running pass 'Function Pass Manager' on module 'bugp.1.ll'.
2.	Running pass 'Expand out variables with struct types' on function '@_read_wrapped_array'

Backtrace from gdb:

#3  0x00007ffff6931c62 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6

#4  0x0000555556a05b08 in llvm::Value::doRAUW (this=0x5555586971a8, New=0x555558693b18, NoMetadata=false)
    at .../src/lib/IR/Value.cpp:374

#5  0x0000555556a05c66 in llvm::Value::replaceAllUsesWith (this=0x5555586971a8, New=0x555558693b18)
    at .../src/lib/IR/Value.cpp:402

#6  0x0000555556f50d65 in ExpandExtractValue (EV=0x5555586971a8, ToErase=0x7fffffffd6d0)
    at .../src/lib/Target/JSBackend/NaCl/ExpandStructRegs.cpp:468

#7  0x0000555556f50efb in ExpandExtractValues (Func=..., Finalize=false)
    at .../src/lib/Target/JSBackend/NaCl/ExpandStructRegs.cpp:485

#8  0x0000555556f5145c in (anonymous namespace)::ExpandStructRegs::runOnFunction (this=0x5555586a47c0, Func=...)
    at .../src/lib/Target/JSBackend/NaCl/ExpandStructRegs.cpp:557

#9  0x0000555556994e30 in llvm::FPPassManager::runOnFunction (this=0x5555586a4880, F=...)
    at .../src/lib/IR/LegacyPassManager.cpp:1513

#10 0x0000555556994fc9 in llvm::FPPassManager::runOnModule (this=0x5555586a4880, M=...)
    at .../src/lib/IR/LegacyPassManager.cpp:1534

#11 0x0000555556995344 in (anonymous namespace)::MPPassManager::runOnModule (this=0x55555868fb60, M=...)
    at .../src/lib/IR/LegacyPassManager.cpp:1590

#12 0x0000555556995a5b in llvm::legacy::PassManagerImpl::run (this=0x5555586a0c70, M=...)
    at .../src/lib/IR/LegacyPassManager.cpp:1693

#13 0x0000555556995c53 in llvm::legacy::PassManager::run (this=0x7fffffffdb10, M=...)
    at .../src/lib/IR/LegacyPassManager.cpp:1724

#14 0x0000555555dc3a16 in compileModule (argv=0x7fffffffe238, Context=...) at .../src/tools/llc/llc.cpp:528

#15 0x0000555555dc2054 in main (argc=3, argv=0x7fffffffe238) at .../src/tools/llc/llc.cpp:285
@TimNN
Copy link
Contributor Author

TimNN commented Apr 6, 2017

I've been debugging a bit, and essentially the problem is, that at some point the following two lines are produced:

%.field = load [2 x i64], [2 x i64]* %.index, align 8
%.elt = extractvalue [2 x i64] %.field, 0

And it then tries to replace elt by field, which obviously doesn't work since field is [2 x i64] and elt is i64.

Note that those two lines passed directly to llc don't produce an assertion, leading me to believe that at some point some other pass needs to be run on the function.

@TimNN
Copy link
Contributor Author

TimNN commented Apr 6, 2017

I've found the problem and a fix, PR incoming.

@TimNN
Copy link
Contributor Author

TimNN commented Apr 7, 2017

This has been fixed.

@TimNN TimNN closed this as completed Apr 7, 2017
bors added a commit to rust-lang/rust that referenced this issue Apr 8, 2017
[WIP] LLVM 4.0 Upgrade

Since nobody has done this yet, I decided to get things started:

**Todo:**

* [ ] push the relevant commits to `rust-lang/llvm` and `rust-lang/compiler-rt`
* [ ] cleanup `.gitmodules`
* [ ] Verify if there are any other commits from `rust-lang/llvm` which need backporting
* [x] Investigate / fix debuginfo ("`<optimized out>`") failures
* [x] Use correct emscripten version in docker image

---

Closes #37609.

---

**Test results:**

* `FAIL`: `IMAGE=armhf-gnu` [travis](https://travis-ci.org/rust-lang/rust/jobs/205860539) (looks to be qemu related, or rather the client / server tools)
* `FAIL`: `IMAGE=emscripten` [travis](https://travis-ci.org/rust-lang/rust/jobs/205978867) (with an updated emcc: one bad emcc optimization: emscripten-core/emscripten-fastcomp#176) ~~[travis](https://travis-ci.org/rust-lang/rust/jobs/205860559) (mainly (only?) due to emcc / rust llvm version mismatch)~~
* `FAIL`: `IMAGE=dist-powerpc64-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514546) (llvm unreachable when compiling core: `Invalid PPC CTR loop!
UNREACHABLE executed at .../PPCCTRLoops.cpp:722!`, reported as [upstream bug #32485](https://bugs.llvm.org//show_bug.cgi?id=32485))
* `SUCCESS/TIMEOUT`: `IMAGE=dist-arm-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514540) (passes locally)
* `SUCCESS/TIMEOUT`: `IMAGE=dist-armv7-aarch64-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514541) (passes locally)
* `SUCCESS`: `IMAGE=arm-android` (fixed)
* `SUCCESS`: `IMAGE=cross`
* `SUCCESS`: `IMAGE=linux-tested-targets`
* `SUCCESS`: `IMAGE=dist-android`
* `SUCCESS`: `IMAGE=dist-freebsd` (fixed)
* `SUCCESS`: `IMAGE=dist-fuchsia`
* `SUCCESS`: `IMAGE=dist-mips-linux`
* `SUCCESS`: `IMAGE=dist-mips64-linux`
* `SUCCESS`: `IMAGE=dist-powerpc-linux`
* `SUCCESS`: `IMAGE=dist-s390x-linux-netbsd` (fixed)
* `SUCCESS`: `IMAGE=dist-x86-linux` (fixed)
* `SUCCESS`: `IMAGE=i686-gnu`
* `SUCCESS`: `IMAGE=i686-gnu-nopt`
* `SUCCESS`: `IMAGE=x86_64-gnu-llvm-3.7`
* `SUCCESS`: `IMAGE=x86_64-gnu`
* `SUCCESS`: `IMAGE=x86_64-gnu-aux`
* `SUCCESS`: `IMAGE=x86_64-gnu-debug`
* `SUCCESS`: `IMAGE=x86_64-gnu-nopt`
* `SUCCESS`: `IMAGE=x86_64-gnu-full-bootstrap`
* `SUCCESS`: `IMAGE=x86_64-gnu-distcheck`
* `SUCCESS`: `IMAGE=x86_64-gnu-incremental`
bors added a commit to rust-lang/rust that referenced this issue Apr 14, 2017
LLVM 4.0 Upgrade

Since nobody has done this yet, I decided to get things started:

**Todo:**

* [ ] push the relevant commits to `rust-lang/llvm` and `rust-lang/compiler-rt`
* [ ] cleanup `.gitmodules`
* [ ] Verify if there are any other commits from `rust-lang/llvm` which need backporting
* [x] Investigate / fix debuginfo ("`<optimized out>`") failures
* [x] Use correct emscripten version in docker image

---

Closes #37609.

---

**Test results:**

* `FAIL`: `IMAGE=armhf-gnu` [travis](https://travis-ci.org/rust-lang/rust/jobs/205860539) (looks to be qemu related, or rather the client / server tools)
* `FAIL`: `IMAGE=emscripten` [travis](https://travis-ci.org/rust-lang/rust/jobs/205978867) (with an updated emcc: one bad emcc optimization: emscripten-core/emscripten-fastcomp#176) ~~[travis](https://travis-ci.org/rust-lang/rust/jobs/205860559) (mainly (only?) due to emcc / rust llvm version mismatch)~~
* `FAIL`: `IMAGE=dist-powerpc64-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514546) (llvm unreachable when compiling core: `Invalid PPC CTR loop!
UNREACHABLE executed at .../PPCCTRLoops.cpp:722!`, reported as [upstream bug #32485](https://bugs.llvm.org//show_bug.cgi?id=32485))
* `SUCCESS/TIMEOUT`: `IMAGE=dist-arm-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514540) (passes locally)
* `SUCCESS/TIMEOUT`: `IMAGE=dist-armv7-aarch64-linux` [travis](https://travis-ci.org/rust-lang/rust/jobs/206514541) (passes locally)
* `SUCCESS`: `IMAGE=arm-android` (fixed)
* `SUCCESS`: `IMAGE=cross`
* `SUCCESS`: `IMAGE=linux-tested-targets`
* `SUCCESS`: `IMAGE=dist-android`
* `SUCCESS`: `IMAGE=dist-freebsd` (fixed)
* `SUCCESS`: `IMAGE=dist-fuchsia`
* `SUCCESS`: `IMAGE=dist-mips-linux`
* `SUCCESS`: `IMAGE=dist-mips64-linux`
* `SUCCESS`: `IMAGE=dist-powerpc-linux`
* `SUCCESS`: `IMAGE=dist-s390x-linux-netbsd` (fixed)
* `SUCCESS`: `IMAGE=dist-x86-linux` (fixed)
* `SUCCESS`: `IMAGE=i686-gnu`
* `SUCCESS`: `IMAGE=i686-gnu-nopt`
* `SUCCESS`: `IMAGE=x86_64-gnu-llvm-3.7`
* `SUCCESS`: `IMAGE=x86_64-gnu`
* `SUCCESS`: `IMAGE=x86_64-gnu-aux`
* `SUCCESS`: `IMAGE=x86_64-gnu-debug`
* `SUCCESS`: `IMAGE=x86_64-gnu-nopt`
* `SUCCESS`: `IMAGE=x86_64-gnu-full-bootstrap`
* `SUCCESS`: `IMAGE=x86_64-gnu-distcheck`
* `SUCCESS`: `IMAGE=x86_64-gnu-incremental`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant