Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,9 +2522,13 @@ InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
Op = RISCV::VADD_VV;
break;
case ISD::SHL:
Op = RISCV::VSLL_VV;
break;
case ISD::SRL:
Op = RISCV::VSRL_VV;
break;
case ISD::SRA:
Op = RISCV::VSLL_VV;
Op = RISCV::VSRA_VV;
break;
case ISD::AND:
case ISD::OR:
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/Analysis/CostModel/RISCV/rvv-shift-cost.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; REQUIRES: riscv-registered-target
; RUN: opt -mtriple=riscv64 -mattr=+v -passes='print<cost-model>' -disable-output < %s 2>&1 | FileCheck %s

define <8 x i32> @shl_cost(<8 x i32> %a, <8 x i32> %b) {
; CHECK-LABEL: 'shl_cost'
; CHECK: Cost Model: Found an estimated cost of
; CHECK: shl <8 x i32>
%r = shl <8 x i32> %a, %b
ret <8 x i32> %r
}

define <8 x i32> @srl_cost(<8 x i32> %a, <8 x i32> %b) {
; CHECK-LABEL: 'srl_cost'
; CHECK: Cost Model: Found an estimated cost of
; CHECK: lshr <8 x i32>
%r = lshr <8 x i32> %a, %b
ret <8 x i32> %r
}

define <8 x i32> @sra_cost(<8 x i32> %a, <8 x i32> %b) {
; CHECK-LABEL: 'sra_cost'
; CHECK: Cost Model: Found an estimated cost of
; CHECK: ashr <8 x i32>
%r = ashr <8 x i32> %a, %b
ret <8 x i32> %r
}
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv-shift-vv.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; REQUIRES: riscv-registered-target

; RUN: llc -mtriple=riscv64 -mattr=+v -O2 -verify-machineinstrs < %s | FileCheck %s

; 我們用 <8 x i32> 並讓位移量來自第二個向量參數,確保走 VV 形式
;(不是 vx/vi)。每個函式只做一次對應的 shift。

; CHECK-LABEL: shl_vv
; CHECK: vsll.vv
define <8 x i32> @shl_vv(<8 x i32> %a, <8 x i32> %b) {
%r = shl <8 x i32> %a, %b
ret <8 x i32> %r
}

; CHECK-LABEL: srl_vv
; CHECK: vsrl.vv
define <8 x i32> @srl_vv(<8 x i32> %a, <8 x i32> %b) {
%r = lshr <8 x i32> %a, %b
ret <8 x i32> %r
}

; CHECK-LABEL: sra_vv
; CHECK: vsra.vv
define <8 x i32> @sra_vv(<8 x i32> %a, <8 x i32> %b) {
%r = ashr <8 x i32> %a, %b
ret <8 x i32> %r
}