Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: void llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `!contains(New, this) && "this->replaceAllUsesWith(expr(this)) is NOT valid!"' failed. #36474

Closed
bluss opened this issue Sep 14, 2016 · 10 comments
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bluss
Copy link
Member

bluss commented Sep 14, 2016

This is a recently introduced ICE that appears with -Copt-level=3

using rustc 1.13.0-nightly (5531c31 2016-09-12)

rustc: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/lib/IR/Value.cpp:373: void llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `!contains(New, this) && "this->replaceAllUsesWith(expr(this)) is NOT valid!"' failed.

Shrunk test case below (original is in ndarray tests/dimension.rs). Use rustc -Copt-level=3 to reproduce.

fn main() {
    remove_axis(&3, 0);
}

trait Dimension {
    fn slice(&self) -> &[usize];
}

impl Dimension for () {
    fn slice(&self) -> &[usize] { &[] }
}

impl Dimension for usize {
    fn slice(&self) -> &[usize] {
        unsafe {
            ::std::slice::from_raw_parts(self, 1)
        }
    }
}

fn remove_axis(value: &usize, axis: usize) -> () {
    let tup = ();
    let mut it = tup.slice().iter();
    for (i, _) in value.slice().iter().enumerate() {
        if i == axis {
            continue;
        }
        it.next();
    }
}

(Edits: Reduced test case further)

@bluss bluss added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 14, 2016
@TimNN
Copy link
Contributor

TimNN commented Sep 14, 2016

Introduced between nightly-2016-08-03 and nightly-2016-08-04 (also occurs on opt-level 2 here) (Changes)

#35174 has lots of llvm changes, so I guess that's a likely candidate to have caused this.

Edit: Just checked and -Z orbit=off does not reproduce, so I rather suspect #35197

@alexcrichton alexcrichton added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 14, 2016
@alexcrichton
Copy link
Member

cc @eddyb

@nagisa
Copy link
Member

nagisa commented Sep 14, 2016

  • Assertion happens inside LLVM pass (instcombine?);
  • Does not reproduce with LLVM 3.8;

This is the IR which causes the assertion to fire:

; Function Attrs: nounwind readnone uwtable
define internal fastcc void @_ZN4test11remove_axis17h518617d2aa05c61eE() unnamed_addr #1 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
entry-block:
  br label %bb7

bb7:                                              ; preds = %bb10.i, %bb12, %bb10, %entry-block
  %iter.sroa.0.0 = phi i64* [ @ref8151, %entry-block ], [ %iter.sroa.0.1, %bb10 ], [ %iter.sroa.0.1, %bb12 ], [ %iter.sroa.0.1, %bb10.i ]
  %iter.sroa.7.0 = phi i64 [ 0, %entry-block ], [ %iter.sroa.7.1, %bb10 ], [ %iter.sroa.7.1, %bb12 ], [ %iter.sroa.7.1, %bb10.i ]
  %it.sroa.0.0 = phi i64* [ getelementptr inbounds ([0 x i64], [0 x i64]* @ref8152, i64 0, i64 0), %entry-block ], [ %it.sroa.0.0, %bb10 ], [ getelementptr inbounds ([0 x i64], [0 x i64]* @ref8152, i64 0, i64 0), %bb12 ], [ %7, %bb10.i ]
  %tmp10.sroa.0.0 = phi i64 [ undef, %entry-block ], [ 0, %bb10 ], [ %tmp10.sroa.0.1, %bb12 ], [ %tmp10.sroa.0.1, %bb10.i ]
  %0 = icmp eq i64* %iter.sroa.0.0, getelementptr inbounds (i64, i64* @ref8151, i64 1)
  br i1 %0, label %"_ZN81_$LT$core..iter..Enumerate$LT$I$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17h32f5bf83064acb8cE.exit", label %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i"

"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i": ; preds = %bb7
  %1 = getelementptr inbounds i64, i64* %iter.sroa.0.0, i64 1
  %2 = add i64 %iter.sroa.7.0, 1
  %3 = ptrtoint i64* %iter.sroa.0.0 to i64
  br label %"_ZN81_$LT$core..iter..Enumerate$LT$I$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17h32f5bf83064acb8cE.exit"

"_ZN81_$LT$core..iter..Enumerate$LT$I$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17h32f5bf83064acb8cE.exit": ; preds = %bb7, %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i"
  %iter.sroa.0.1 = phi i64* [ %1, %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i" ], [ getelementptr inbounds (i64, i64* @ref8151, i64 1), %bb7 ]
  %iter.sroa.7.1 = phi i64 [ %2, %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i" ], [ %iter.sroa.7.0, %bb7 ]
  %tmp10.sroa.6.0 = phi i64 [ %3, %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i" ], [ 0, %bb7 ]
  %tmp10.sroa.0.1 = phi i64 [ %iter.sroa.7.0, %"_ZN91_$LT$core..slice..Iter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17hbcf540387e7bb34eE.exit.i" ], [ %tmp10.sroa.0.0, %bb7 ]
  %4 = inttoptr i64 %tmp10.sroa.6.0 to i64*
  %switchtmp = icmp eq i64* %4, null
  br i1 %switchtmp, label %bb9, label %bb10

bb9:                                              ; preds = %"_ZN81_$LT$core..iter..Enumerate$LT$I$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17h32f5bf83064acb8cE.exit"
  ret void

bb10:                                             ; preds = %"_ZN81_$LT$core..iter..Enumerate$LT$I$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17h32f5bf83064acb8cE.exit"
  %5 = icmp eq i64 %tmp10.sroa.0.1, 0
  br i1 %5, label %bb7, label %bb12

bb12:                                             ; preds = %bb10
  %6 = icmp eq i64* %it.sroa.0.0, getelementptr inbounds ([0 x i64], [0 x i64]* @ref8152, i64 0, i64 0)
  br i1 %6, label %bb7, label %bb10.i

bb10.i:                                           ; preds = %bb12
  %7 = getelementptr inbounds i64, i64* %it.sroa.0.0, i64 1
  br label %bb7
}

Most likely A-llvm stuff.

@eddyb eddyb added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Sep 15, 2016
@nagisa
Copy link
Member

nagisa commented Sep 15, 2016

@nagisa
Copy link
Member

nagisa commented Sep 15, 2016

Fixed in https://reviews.llvm.org/rL281650, need to update/patch our LLVM.

@nrc
Copy link
Member

nrc commented Sep 15, 2016

Discussed in compiler meeting, we prefer to wait for the LLVM upgrade to fix this. But if it looks like we hit beta without it, we can backport the patch to our LLVM.

triage: p-medium

assign @nagisa in my head, but not on GitHub (because I can't)

@nrc nrc added P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed I-nominated regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Sep 15, 2016
@nrc
Copy link
Member

nrc commented Sep 15, 2016

Turns out I was too eager - this in fact affects beta, and so we should backport the LLVM patch now.

@nrc nrc self-assigned this Sep 15, 2016
@nrc
Copy link
Member

nrc commented Sep 15, 2016

assigning to myself as a proxy for @nagisa

@nagisa nagisa mentioned this issue Sep 15, 2016
nagisa added a commit to nagisa/rust that referenced this issue Sep 17, 2016
bors added a commit that referenced this issue Sep 17, 2016
Up the LLVM

Fixes #36474

The relevant patch to rust-llvm is at rust-lang/llvm#51

r? @alexcrichton
@bluss
Copy link
Member Author

bluss commented Sep 18, 2016

Confirming that the original ndarray tests/dimension.rs issue was fixed by rustc 1.13.0-nightly (32571c0 2016-09-17)

brson pushed a commit to brson/rust that referenced this issue Sep 19, 2016
@sylvestre
Copy link
Contributor

I asked for this patch to be backported in 3.9.1: https://llvm.org/bugs/show_bug.cgi?id=30261#c14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants