Skip to content

Commit dd2c1eb

Browse files
committed
[RISCV] Correct RISCVTTIImpl::getIntImmCostInst for Zba
zext.w is only available on RV64.
1 parent 02c804d commit dd2c1eb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ InstructionCost RISCVTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
207207
if (Imm == UINT64_C(0xffff) && ST->hasStdExtZbb())
208208
return TTI::TCC_Free;
209209
// zext.w
210-
if (Imm == UINT64_C(0xffffffff) && ST->hasStdExtZba())
210+
if (ST->isRV64() && Imm == UINT64_C(0xffffffff) && ST->hasStdExtZba())
211211
return TTI::TCC_Free;
212212
// bclri
213213
if (ST->hasStdExtZbs() && (~Imm).isPowerOf2())

llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt -mtriple=riscv32-unknown-elf -S -passes=consthoist < %s | FileCheck %s
2-
; RUN: opt -mtriple=riscv64-unknown-elf -S -passes=consthoist < %s | FileCheck %s
1+
; RUN: opt -mtriple=riscv32-unknown-elf -S -passes=consthoist < %s | FileCheck %s -check-prefixes=CHECK,RV32I
2+
; RUN: opt -mtriple=riscv64-unknown-elf -S -passes=consthoist < %s | FileCheck %s -check-prefixes=CHECK,RV64I
33

44
; Check that we don't hoist immediates with small values.
55
define i64 @test1(i64 %a) nounwind {
@@ -64,10 +64,13 @@ define i64 @test7(i64 %a) nounwind {
6464
ret i64 %2
6565
}
6666

67-
; Check that we don't hoist zext.w with Zba.
67+
; Check that we don't hoist zext.w with Zba on riscv64-unknown-elf.
6868
define i64 @test8(i64 %a) nounwind "target-features"="+zba" {
69-
; CHECK-LABEL: test8
70-
; CHECK: and i64 %a, 4294967295
69+
; RV32I-LABEL: test8
70+
; RVI32: %const = bitcast i64 4294967295 to i64
71+
72+
; RV64I-LABEL: test8
73+
; RV64I: and i64 %a, 4294967295
7174
%1 = and i64 %a, 4294967295
7275
%2 = and i64 %1, 4294967295
7376
ret i64 %2

0 commit comments

Comments
 (0)