Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMDGPU] mul used with v1i8 / v1i16 causes crash during IR optimizations due to type mismatch #58331

Closed
HazyFish opened this issue Oct 12, 2022 · 3 comments

Comments

@HazyFish
Copy link
Contributor

HazyFish commented Oct 12, 2022

Description

For amdgcn, when mul is used with v1i8 / v1i16 causes crash during IR optimizations due to type mismatch.
The problem doesn't exist for v1i32.

Cause

In function AMDGPUCodeGenPrepare::replaceMulWithMul24,

Value *NewVal = insertValues(Builder, Ty, ResultVals);
NewVal->takeName(&I);
I.replaceAllUsesWith(NewVal);
I.eraseFromParent();

insertValues will turn a vector of size 1 into a scalar due to the following logic:

static Value *insertValues(IRBuilder<> &Builder,
Type *Ty,
SmallVectorImpl<Value *> &Values) {
if (Values.size() == 1)
return Values[0];

As a result, when replaceAllUsesWith is called, the assertion New->getType() == getType() && "replaceAllUses of value with new value of different type!" failed because the old type (vector) and the new type (scaler) are not the same.

Minimal Reproduction

https://godbolt.org/z/48n93sTWf

Code

define <1 x i16> @f(<1 x i16> %0) {
BB:
  %B = mul <1 x i16> %0, <i16 42>
  ret <1 x i16> %B
}

Stack Trace

llc: /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/Value.cpp:506: void llvm::Value::doRAUW(llvm::Value *, llvm::Value::ReplaceMetadataUses): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ./llvm-project/build-debug/bin/llc ./crash-reports/dagisel-amdgcn/1.ll -mtriple=amdgcn
1.	Running pass 'Function Pass Manager' on module './crash-reports/dagisel-amdgcn/1.ll'.
2.	Running pass 'AMDGPU IR optimizations' on function '@f'
 #0 0x0000000003af78fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
 #1 0x0000000003af7aab PrintStackTraceSignalHandler(void*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000000003af60f6 llvm::sys::RunSignalHandlers() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x0000000003af81d5 SignalHandler(int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007fe6d0720980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fe6cf610e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007fe6cf6127f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007fe6cf6023fa __assert_fail_base /build/glibc-uZu3wS/glibc-2.27/assert/assert.c:89:0
 #8 0x00007fe6cf602472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x00000000030596bd llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/Value.cpp:0:3
#10 0x0000000003059cd2 llvm::Value::replaceAllUsesWith(llvm::Value*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/Value.cpp:534:1
#11 0x0000000001b19503 (anonymous namespace)::AMDGPUCodeGenPrepare::replaceMulWithMul24(llvm::BinaryOperator&) const /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp:573:3
#12 0x0000000001b17cdd (anonymous namespace)::AMDGPUCodeGenPrepare::visitBinaryOperator(llvm::BinaryOperator&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp:1240:7
#13 0x0000000001b167bd llvm::InstVisitor<(anonymous namespace)::AMDGPUCodeGenPrepare, bool>::visitMul(llvm::BinaryOperator&) /home/henry/aflplusplus-isel/llvm-project/llvm/include/llvm/IR/Instruction.def:151:1
#14 0x0000000001b1600c llvm::InstVisitor<(anonymous namespace)::AMDGPUCodeGenPrepare, bool>::visit(llvm::Instruction&) /home/henry/aflplusplus-isel/llvm-project/llvm/include/llvm/IR/Instruction.def:151:1
#15 0x0000000001b15cf2 (anonymous namespace)::AMDGPUCodeGenPrepare::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp:1440:21
#16 0x0000000002f995d6 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#17 0x0000000002f9e402 llvm::FPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#18 0x0000000002f99ea9 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#19 0x0000000002f99a1d llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#20 0x0000000002f9e6e1 llvm::legacy::PassManager::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#21 0x0000000000d391ec compileModule(char**, llvm::LLVMContext&) /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:737:41
#22 0x0000000000d37592 main /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:418:13
#23 0x00007fe6cf5f3c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#24 0x0000000000d36d9a _start (./llvm-project/build-debug/bin/llc+0xd36d9a)
@HazyFish HazyFish changed the title [AMDGPU] mul used with v1i16 causes crash during IR optimizations due to type mismatch [AMDGPU] mul used with v1i8 / v1i16 causes crash during IR optimizations due to type mismatch Oct 12, 2022
@arsenm
Copy link
Contributor

arsenm commented Oct 12, 2022

https://reviews.llvm.org/D135821

@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2022

@llvm/issue-subscribers-backend-amdgpu

@arsenm
Copy link
Contributor

arsenm commented Oct 13, 2022

Fixed by 838fd61

@arsenm arsenm closed this as completed Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants