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

Crash in InstCombine after and/or const expressions marked undesirable

Open ormris opened this issue 3 years ago • 3 comments

@nikic We bisected the crash to 0cab8d20417c0e2ccc1ffc5505e080126f5de8e6. Steps to reproduce below.

$ cat test.ll
target triple = "aarch64-none-linux"

%struct.e = type { %struct.anon.16, %struct.f }
%struct.anon.16 = type { ptr }
%struct.f = type { %struct.d, i32 }
%struct.d = type { ptr, i32, i32, ptr }

@g = external global i32

define void @a(ptr %ident) {
entry:
  tail call void @b(ptr %ident)
  ret void
}

define void @b(ptr %wchan) {
entry:
  %0 = ptrtoint ptr %wchan to i32
  %shr = lshr i32 %0, 8
  %xor = xor i32 %shr, %0
  %and = and i32 %xor, 1
  %h = getelementptr [256 x %struct.e], ptr null, i32 0, i32 %and, i32 1, i32 1
  %1 = load volatile i32, ptr %h, align 4
  ret void
}

define void @c() {
entry:
  tail call void @a(ptr @g)
  ret void
}
$ opt -O2 -o opt.ll test.ll
Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:\llvm-project\llvm\include\llvm/Support/Casting.h, line 578
...
$                                                                                                          

ormris avatar Jul 26 '23 01:07 ormris

Reduced:

; RUN: opt -S -passes=instcombine < %s
@g = external global i32

define i32 @test() {
  %and = and i32 xor (i32 lshr (i32 ptrtoint (ptr @g to i32), i32 8), i32 ptrtoint (ptr @g to i32)), 1
  ret i32 %and
}

nikic avatar Jul 27 '23 07:07 nikic

Candidate patch: https://reviews.llvm.org/D156401

nikic avatar Jul 27 '23 08:07 nikic

The referenced change has long since landed, and the original patch was reapplied after that.

nikic avatar Aug 17 '23 13:08 nikic