Skip to content

[InstCombine] Assertion failed in visitBitCastBitwiseLogic due to type mismatch during constant folding #179626

@varev-dev

Description

@varev-dev

https://godbolt.org/z/q6TEvboYM
opt crashes with an assertion failure in InstCombine when processing a bitwise operation involving a bitcast of "exotic" vector type (e.g., casting <3 x i32> to <4 x i24>).

opt -passes=instcombine repro.ll
define void @crash() {
  %LGV = load <3 x i32>, ptr addrspace(1) null, align 16
  %B1 = xor <3 x i32> %LGV, splat (i32 1)
  %1 = bitcast <3 x i32> %B1 to i96
  %2 = trunc i96 %1 to i24
  %3 = bitcast i24 %2 to <3 x i8>
  %B4 = lshr <3 x i8> zeroinitializer, %3
  store <3 x i8> %B4, ptr addrspace(1) null, align 4
  ret void
}

The crash occurs because the Constant Folding mechanism seems to incorrectly handle bitcasts for these vector types, returning a constant with a mismatching type (wrong element count/total bit width) compared to the requested destination type.

This triggers a type mismatch assertion when InstCombine attmepts to create the new binary operator.

Crash Log

opt: .../llvm-project/llvm/lib/IR/Instructions.cpp:2707: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && "Cannot create binary operator with two operands of differing type!"' failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions