Skip to content

Commit f7bfa58

Browse files
authored
[SPIR-V] Fix 64-bit integer literal printing (#66686)
Previously, the SPIR-V instruction printer was always printing the first operand of an `OpConstant`'s literal value as one of the fixed operands. This is incorrect for 64-bit values, where the first operand is actually the value's lower-order word and should be combined with the following higher-order word before printing. This change fixes that issue by waiting to print the last fixed operand of `OpConstant` instructions until the variadic operands are ready to be printed, then using `NumFixedOps - 1` as the starting operand index for the literal value operands. Depends on D156049
1 parent c1b9974 commit f7bfa58

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
169169
}
170170
case SPIRV::OpConstantI:
171171
case SPIRV::OpConstantF:
172-
printOpConstantVarOps(MI, NumFixedOps, OS);
172+
// The last fixed operand along with any variadic operands that follow
173+
// are part of the variable value.
174+
printOpConstantVarOps(MI, NumFixedOps - 1, OS);
173175
break;
174176
default:
175177
printRemainingVariableOps(MI, NumFixedOps, OS);

llvm/lib/Target/SPIRV/SPIRVInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def ConstPseudoNull: IntImmLeaf<i64, [{ return Imm.isZero(); }]>;
217217

218218
multiclass IntFPImm<bits<16> opCode, string name> {
219219
def I: Op<opCode, (outs ID:$dst), (ins TYPE:$type, ID:$src, variable_ops),
220-
"$dst = "#name#" $type $src", [(set ID:$dst, (assigntype PseudoConstI:$src, TYPE:$type))]>;
220+
"$dst = "#name#" $type", [(set ID:$dst, (assigntype PseudoConstI:$src, TYPE:$type))]>;
221221
def F: Op<opCode, (outs ID:$dst), (ins TYPE:$type, fID:$src, variable_ops),
222-
"$dst = "#name#" $type $src", [(set ID:$dst, (assigntype PseudoConstF:$src, TYPE:$type))]>;
222+
"$dst = "#name#" $type", [(set ID:$dst, (assigntype PseudoConstF:$src, TYPE:$type))]>;
223223
}
224224

225225
def OpConstantTrue: Op<41, (outs ID:$dst), (ins TYPE:$src_ty), "$dst = OpConstantTrue $src_ty",

llvm/test/CodeGen/SPIRV/atomicrmw.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
22

33
; CHECK: %[[#Int:]] = OpTypeInt 32 0
4-
; CHECK-DAG: %[[#Scope_Device:]] = OpConstant %[[#Int]] 1 {{$}}
4+
; CHECK-DAG: %[[#Scope_Device:]] = OpConstant %[[#Int]] 1{{$}}
55
; CHECK-DAG: %[[#MemSem_Relaxed:]] = OpConstant %[[#Int]] 0
66
; CHECK-DAG: %[[#MemSem_Acquire:]] = OpConstant %[[#Int]] 2
7-
; CHECK-DAG: %[[#MemSem_Release:]] = OpConstant %[[#Int]] 4 {{$}}
7+
; CHECK-DAG: %[[#MemSem_Release:]] = OpConstant %[[#Int]] 4{{$}}
88
; CHECK-DAG: %[[#MemSem_AcquireRelease:]] = OpConstant %[[#Int]] 8
99
; CHECK-DAG: %[[#MemSem_SequentiallyConsistent:]] = OpConstant %[[#Int]] 16
1010
; CHECK-DAG: %[[#Value:]] = OpConstant %[[#Int]] 42

llvm/test/CodeGen/SPIRV/constant/local-integers-constants.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ define i64 @getLargeConstantI64() {
4444
; CHECK-DAG: %[[#CST_I8:]] = OpConstant %[[#I8]] 2
4545
; CHECK-DAG: %[[#CST_I16:]] = OpConstant %[[#I16]] 65478
4646
; CHECK-DAG: %[[#CST_I32:]] = OpConstant %[[#I32]] 42
47-
; CHECK-DAG: %[[#CST_I64:]] = OpConstant %[[#I64]] 123456789 0
48-
; CHECK-DAG: %[[#CST_LARGE_I64:]] = OpConstant %[[#I64]] 0 8
47+
; CHECK-DAG: %[[#CST_I64:]] = OpConstant %[[#I64]] 123456789
48+
; CHECK-DAG: %[[#CST_LARGE_I64:]] = OpConstant %[[#I64]] 34359738368
4949

5050
; CHECK: %[[#GET_I8]] = OpFunction %[[#I8]]
5151
; CHECK: OpReturnValue %[[#CST_I8]]

llvm/test/CodeGen/SPIRV/lshr-constexpr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; CHECK-SPIRV: %[[#type_vec:]] = OpTypeVector %[[#type_int32]] 2
66
; CHECK-SPIRV: %[[#const1:]] = OpConstant %[[#type_int32]] 1
77
; CHECK-SPIRV: %[[#vec_const:]] = OpConstantComposite %[[#type_vec]] %[[#const1]] %[[#const1]]
8-
; CHECK-SPIRV: %[[#const32:]] = OpConstant %[[#type_int64]] 32 0
8+
; CHECK-SPIRV: %[[#const32:]] = OpConstant %[[#type_int64]] 32
99

1010
; CHECK-SPIRV: %[[#bitcast_res:]] = OpBitcast %[[#type_int64]] %[[#vec_const]]
1111
; CHECK-SPIRV: %[[#shift_res:]] = OpShiftRightLogical %[[#type_int64]] %[[#bitcast_res]] %[[#const32]]

llvm/test/CodeGen/SPIRV/uitofp-with-bool.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
; SPV-DAG: %[[#mone_16:]] = OpConstant %[[#int_16]] 65535
4242
; SPV-DAG: %[[#mone_32:]] = OpConstant %[[#int_32]] 4294967295
4343
; SPV-DAG: %[[#zero_64:]] = OpConstantNull %[[#int_64]]
44-
; SPV-DAG: %[[#mone_64:]] = OpConstant %[[#int_64]] 4294967295 4294967295
44+
; SPV-DAG: %[[#mone_64:]] = OpConstant %[[#int_64]] 18446744073709551615
4545
; SPV-DAG: %[[#one_8:]] = OpConstant %[[#int_8]] 1
4646
; SPV-DAG: %[[#one_16:]] = OpConstant %[[#int_16]] 1
47-
; SPV-DAG: %[[#one_64:]] = OpConstant %[[#int_64]] 1 0
47+
; SPV-DAG: %[[#one_64:]] = OpConstant %[[#int_64]] 1
4848
; SPV-DAG: %[[#void:]] = OpTypeVoid
4949
; SPV-DAG: %[[#float:]] = OpTypeFloat 32
5050
; SPV-DAG: %[[#bool:]] = OpTypeBool

0 commit comments

Comments
 (0)