llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

LoopDeletion causes an assert `use_empty() && "Uses remain when a value is destroyed!"'

Open serguei-katkov opened this issue 8 years ago • 6 comments

Bugzilla Link 35884
Resolution FIXED
Resolved on Jan 11, 2018 23:53
Version trunk
OS All
CC @annamthomas,@hfinkel

Extended Description

For the following simple reproducer: define i64 @​foo() { entry: br label %badloop badloop: %indvar1 = phi i64 [ 3, %entry ], [ %indvar2, %badloop_iter ] %check = icmp ult i64 %indvar1, 400 br i1 %check, label %badloop_iter, label %loopexit badloop_iter: %indvar2 = add i64 %indvar1, 1 %baddef = add i64 0, 0 br label %badloop loopexit: ret i64 0 deadcode: ret i64 %baddef }

opt -S -loop-deletion test.ll

While deleting: i64 %baddef Use still stuck around after Def is destroyed: ret i64 %baddef opt: ../../lib/IR/Value.cpp:92: llvm::Value::~Value(): Assertion `use_empty() && "Uses remain when a value is destroyed!"' failed.

The cause of this is that %baddef is defined in BB which does not dominate exit and as a result LCCSA does not create a Phi node for it.

As a result LoopDeletion detects that loop is invariant and tries to delete it.

Assert happens when %baddef instruction is deleted due to it has use in unreachable block.

The IR is well-formed because %baddef dominates all instructions in unreachable block.

serguei-katkov avatar Jan 10 '18 08:01 serguei-katkov

Landed at rL322357.

serguei-katkov avatar Jan 12 '18 07:01 serguei-katkov

Please take a look at https://reviews.llvm.org/D41943.

serguei-katkov avatar Jan 11 '18 11:01 serguei-katkov

The analysis seems correct, feel free to submit a review and I'll take a look (if you have issues, I can probably take a look at the bug altogether as I fixed a bunch of these already).

http://lists.llvm.org/pipermail/llvm-dev/2018-January/120332.html :)

Oh, missed that one, too early :) yes, feel free to go ahead with that fix for loop deletion. I'll be happy to review the patch.

llvmbot avatar Jan 10 '18 15:01 llvmbot

The analysis seems correct, feel free to submit a review and I'll take a look (if you have issues, I can probably take a look at the bug altogether as I fixed a bunch of these already).

http://lists.llvm.org/pipermail/llvm-dev/2018-January/120332.html :)

annamthomas avatar Jan 10 '18 15:01 annamthomas

The analysis seems correct, feel free to submit a review and I'll take a look (if you have issues, I can probably take a look at the bug altogether as I fixed a bunch of these already).

llvmbot avatar Jan 10 '18 15:01 llvmbot

Serguei, feel free to take a crack at it, given you've figured out the hard part :)

Otherwise, if you'd like, I can fix this.

annamthomas avatar Jan 10 '18 14:01 annamthomas