diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp index 7d1136bb9beba..75c631055ae2d 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp @@ -82,7 +82,7 @@ InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost( BasicTTIImplBase::getArithmeticInstrCost( Opcode, Ty, CostKind, Op1Info, Op2Info); - if (auto *VTy = dyn_cast(Ty)) { + if (auto *VTy = dyn_cast(Ty)) { switch (Opcode) { case Instruction::LShr: case Instruction::AShr: @@ -92,7 +92,7 @@ InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost( // approximation. if (!Op2Info.isUniform()) Cost = - cast(VTy)->getNumElements() * + VTy->getNumElements() * (TargetTransformInfo::TCC_Basic + getArithmeticInstrCost(Opcode, VTy->getElementType(), CostKind) + TargetTransformInfo::TCC_Basic); diff --git a/llvm/test/Analysis/CostModel/WebAssembly/vector-shift.ll b/llvm/test/Analysis/CostModel/WebAssembly/vector-shift.ll new file mode 100644 index 0000000000000..97f2a94b7b460 --- /dev/null +++ b/llvm/test/Analysis/CostModel/WebAssembly/vector-shift.ll @@ -0,0 +1,42 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6 +; RUN: opt -mtriple=wasm32-unknown-unknown -mattr=+simd128 \ +; RUN: -passes='print' -disable-output < %s 2>&1 | FileCheck %s + +define void @fixed_non_uniform(<4 x i32> %x, <4 x i32> %amount) { +; CHECK-LABEL: 'fixed_non_uniform' +; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %shl = shl <4 x i32> %x, %amount +; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %lshr = lshr <4 x i32> %x, %amount +; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %ashr = ashr <4 x i32> %x, %amount +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %shl = shl <4 x i32> %x, %amount + %lshr = lshr <4 x i32> %x, %amount + %ashr = ashr <4 x i32> %x, %amount + ret void +} + +define void @scalable_uniform( %x) { +; CHECK-LABEL: 'scalable_uniform' +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %shl = shl %x, splat (i32 1) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %lshr = lshr %x, splat (i32 1) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %ashr = ashr %x, splat (i32 1) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %shl = shl %x, splat (i32 1) + %lshr = lshr %x, splat (i32 1) + %ashr = ashr %x, splat (i32 1) + ret void +} + +define void @scalable_non_uniform( %x, %amount) { +; CHECK-LABEL: 'scalable_non_uniform' +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %shl = shl %x, %amount +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %lshr = lshr %x, %amount +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %ashr = ashr %x, %amount +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %shl = shl %x, %amount + %lshr = lshr %x, %amount + %ashr = ashr %x, %amount + ret void +}