llvm / llvm-project

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

[AMDGPU] Assertion "Testing equality of non-equal types!" hit in GVN pass #103500

Closed jhuber6 closed 3 months ago

jhuber6 commented 3 months ago

The following code is a reduced case from the libc++ lexicographical comparison test, https://godbolt.org/z/MnjWbK3ca. This fails when the GVN pass attempts to compare the two values from the GEP. I reduced it further, but wasn't sure if it was the same issue so I figured I'd show both https://godbolt.org/z/hE6d6P6s3, this one is shorter.

define void @iterator(ptr addrspace(5) %0, i64 %1, i32 %2) {
  %4 = addrspacecast ptr addrspace(5) %0 to ptr
  %5 = getelementptr i8, ptr addrspace(5) %0, i32 16
  %6 = getelementptr i8, ptr %4, i64 %1
  %7 = getelementptr i8, ptr addrspace(5) %5, i32 %2
  %8 = load i32, ptr %6, align 4
  %9 = load i32, ptr addrspace(5) %7, align 4
  %10 = icmp slt i32 %8, %9
  ret void
}
$ opt -passes=gvn -mtriple=amdgcn-amd-amdhsa bug.llopt: /root/llvm-project/llvm/lib/Analysis/ValueTracking.cpp:313: bool llvm::isKnownNonEqual(const llvm::Value*, const llvm::Value*, const llvm::DataLayout&, llvm::AssumptionCache*, const llvm::Instruction*, const llvm::DominatorTree*, bool): Assertion `V1->getType() == V2->getType() && "Testing equality of non-equal types!"' failed.
 #0 0x0000000004f49178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f49178)
 #1 0x0000000004f468ec SignalHandler(int) Signals.cpp:0:0
 #2 0x000073c6b4c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000073c6b4c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000073c6b4c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000073c6b4c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000073c6b4c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000073c6b4c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000046e330c (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x46e330c)
 #9 0x00000000043828c3 llvm::BasicAAResult::aliasGEP(llvm::GEPOperator const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::Value const*, llvm::AAQueryInfo&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43828c3)
#10 0x0000000004382cd1 llvm::BasicAAResult::aliasCheckRecursive(llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::AAQueryInfo&, llvm::Value const*, llvm::Value const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4382cd1)
#11 0x0000000004385337 llvm::BasicAAResult::aliasCheck(llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::AAQueryInfo&, llvm::Instruction const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4385337)
#12 0x0000000004385917 llvm::BasicAAResult::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&, llvm::AAQueryInfo&, llvm::Instruction const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4385917)
llvmbot commented 3 months ago

@llvm/issue-subscribers-backend-amdgpu

Author: Joseph Huber (jhuber6)

The following code is a reduced case from the libc++ lexicographical comparison test, https://godbolt.org/z/MnjWbK3ca. This fails when the GVN pass attempts to compare the two values from the GEP. I reduced it further, but wasn't sure if it was the same issue so I figured I'd show both https://godbolt.org/z/hE6d6P6s3, this one is shorter. ```llvm define void @iterator(ptr addrspace(5) %0, i64 %1, i32 %2) { %4 = addrspacecast ptr addrspace(5) %0 to ptr %5 = getelementptr i8, ptr addrspace(5) %0, i32 16 %6 = getelementptr i8, ptr %4, i64 %1 %7 = getelementptr i8, ptr addrspace(5) %5, i32 %2 %8 = load i32, ptr %6, align 4 %9 = load i32, ptr addrspace(5) %7, align 4 %10 = icmp slt i32 %8, %9 ret void } ``` ```console $ opt -passes=gvn -mtriple=amdgcn-amd-amdhsa bug.llopt: /root/llvm-project/llvm/lib/Analysis/ValueTracking.cpp:313: bool llvm::isKnownNonEqual(const llvm::Value*, const llvm::Value*, const llvm::DataLayout&, llvm::AssumptionCache*, const llvm::Instruction*, const llvm::DominatorTree*, bool): Assertion `V1->getType() == V2->getType() && "Testing equality of non-equal types!"' failed. #0 0x0000000004f49178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f49178) #1 0x0000000004f468ec SignalHandler(int) Signals.cpp:0:0 #2 0x000073c6b4c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x000073c6b4c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x000073c6b4c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x000073c6b4c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x000073c6b4c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #7 0x000073c6b4c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #8 0x00000000046e330c (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x46e330c) #9 0x00000000043828c3 llvm::BasicAAResult::aliasGEP(llvm::GEPOperator const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::Value const*, llvm::AAQueryInfo&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43828c3) #10 0x0000000004382cd1 llvm::BasicAAResult::aliasCheckRecursive(llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::AAQueryInfo&, llvm::Value const*, llvm::Value const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4382cd1) #11 0x0000000004385337 llvm::BasicAAResult::aliasCheck(llvm::Value const*, llvm::LocationSize, llvm::Value const*, llvm::LocationSize, llvm::AAQueryInfo&, llvm::Instruction const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4385337) #12 0x0000000004385917 llvm::BasicAAResult::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&, llvm::AAQueryInfo&, llvm::Instruction const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4385917) ```
arsenm commented 3 months ago

BasicAA issue, reproduces with just opt -S -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info