Skip to content

[InstCombine] Miscompilation with llvm.assume in unreachable blocks #97330

Closed
@dtcxzyw

Description

@dtcxzyw

Reproducer: https://alive2.llvm.org/ce/z/zKvpXV

; bin/opt -passes=instcombine reduced.ll -S
define i16 @src(i16 %g, ptr %e, ptr %d) {
entry:
  %0 = load i64, ptr %d, align 8
  %conv = trunc i64 %0 to i16
  %tobool.not.i = icmp eq i16 %g, 0
  br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i

for.cond.preheader.i:
  %cmp5.i = icmp ne i16 %g, %conv
  %conv6.i = zext i1 %cmp5.i to i32
  store i32 %conv6.i, ptr %e, align 4
  %cmp7.i = icmp eq i64 %0, 1
  call void @llvm.assume(i1 %cmp7.i)
  unreachable

i.exit:
  ret i16 %conv
}
define i16 @tgt(i16 %g, ptr %e, ptr %d) {
entry:
  %tobool.not.i = icmp eq i16 %g, 0
  br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i

for.cond.preheader.i:                             ; preds = %entry
  unreachable

i.exit:                                           ; preds = %entry
  ret i16 1
}

llvm version: a8e1c3e

cc @nikic

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions