llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.44k stars 12.16k forks source link

"Instruction does not dominate all uses" with opt -disable-basicaa -loop-versioning #36998

Open mikaelholmen opened 6 years ago

mikaelholmen commented 6 years ago
Bugzilla Link 37650
Version unspecified
OS Linux
Attachments reproducer

Extended Description

opt -S -o - bbi-14805.ll -disable-basicaa -loop-versioning

gives

Instruction does not dominate all uses! %inc = add nsw i16 undef, 1 store i16 %inc, i16* @​c, align 1 LLVM ERROR: Broken function found, compilation aborted!

Found when running random passes/flags on random input. We don't normally use -disable-basicaa -loop-versioning.

This happens also with some old opt binary built in Nov 2016.

fhahn commented 2 years ago

Still reproduces with -passes=loop-versioning -aa-pipeline='': https://clang.godbolt.org/z/xMKo5P989

VedantParanjape commented 2 weeks ago
target triple = "x86_64-unknown-linux-gnu"

@a = external global i16, align 1
@b = external global i16, align 1
@c = external global i16, align 1

define void @f2() {
entry:
  br label %for.body

for.body:                                         ; preds = %for.body, %entry
  %0 = load i16, ptr @a, align 1
  store i16 %0, ptr @b, align 1
  %inc = add nsw i16 undef, 1
  br i1 false, label %for.body, label %for.cond.for.end_crit_edge

for.cond.for.end_crit_edge:                       ; preds = %for.body
  %split2 = phi i16 [ %inc, %for.body ]
  store i16 %inc, ptr @c, align 1
  ret void
}

Converted the testcase to opaque pointers. Able to reproduce with opt -passes=loop-versioning -aa-pipeline='' crash.ll

I want to work on this issue, can I assign this to self?

VedantParanjape commented 2 weeks ago

Still reproduces with -passes=loop-versioning -aa-pipeline='': https://clang.godbolt.org/z/xMKo5P989

The IR ins't in LCSSA form, in the critical edge, store uses inc which is a value defined inside the loop.

VedantParanjape commented 2 weeks ago

I have pushed a fix for this, thanks (cc: @fhahn and @aeubanks) (https://github.com/llvm/llvm-project/pull/116443)

Thanks, Vedant