Skip to content

Commit c4be885

Browse files
committed
Revert "Translate icmp eq and icmp ne to PtrEqual and PtrNotEqual respectively (#2511)"
This reverts commit 992e4be.
1 parent ae98d12 commit c4be885

File tree

4 files changed

+11
-58
lines changed

4 files changed

+11
-58
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,14 +1508,9 @@ SPIRVInstruction *LLVMToSPIRVBase::transCmpInst(CmpInst *Cmp,
15081508
auto *Op0 = Cmp->getOperand(0);
15091509
SPIRVValue *TOp0 = transValue(Op0, BB);
15101510
SPIRVValue *TOp1 = transValue(Cmp->getOperand(1), BB);
1511+
// TODO: once the translator supports SPIR-V 1.4, update the condition below:
1512+
// if (/* */->isPointerTy() && /* it is not allowed to use SPIR-V 1.4 */)
15111513
if (Op0->getType()->isPointerTy()) {
1512-
auto P = Cmp->getPredicate();
1513-
if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4) &&
1514-
(P == ICmpInst::ICMP_EQ || P == ICmpInst::ICMP_NE) &&
1515-
Cmp->getOperand(1)->getType()->isPointerTy()) {
1516-
Op OC = P == ICmpInst::ICMP_EQ ? OpPtrEqual : OpPtrNotEqual;
1517-
return BM->addBinaryInst(OC, transType(Cmp->getType()), TOp0, TOp1, BB);
1518-
}
15191514
unsigned AS = cast<PointerType>(Op0->getType())->getAddressSpace();
15201515
SPIRVType *Ty = transType(getSizetType(AS));
15211516
TOp0 = BM->addUnaryInst(OpConvertPtrToU, Ty, TOp0, BB);

llvm-spirv/test/ComparePointers.cl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ kernel void test(int global *in, int global *in2) {
99
return;
1010
}
1111
// RUN: %clang_cc1 -triple spir64 -x cl -cl-std=CL2.0 -O0 -emit-llvm-bc %s -o %t.bc
12-
// RUN: llvm-spirv %t.bc --spirv-max-version=1.3 -o %t.spv
13-
// RUN: spirv-val %t.spv
14-
// RUN: llvm-spirv %t.bc -spirv-text --spirv-max-version=1.3 -o %t.spt
12+
// RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
1513
// RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
16-
1714
// RUN: llvm-spirv %t.bc -o %t.spv
1815
// RUN: spirv-val %t.spv
19-
// RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
20-
// RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV-14
2116

2217
// CHECK-SPIRV:ConvertPtrToU
2318
// CHECK-SPIRV:ConvertPtrToU
@@ -31,12 +26,3 @@ kernel void test(int global *in, int global *in2) {
3126
// CHECK-SPIRV:ConvertPtrToU
3227
// CHECK-SPIRV:ConvertPtrToU
3328
// CHECK-SPIRV:ULessThan
34-
35-
// CHECK-SPIRV-14: PtrNotEqual
36-
// CHECK-SPIRV-14: PtrEqual
37-
// CHECK-SPIRV-14:ConvertPtrToU
38-
// CHECK-SPIRV-14:ConvertPtrToU
39-
// CHECK-SPIRV-14:UGreaterThan
40-
// CHECK-SPIRV-14:ConvertPtrToU
41-
// CHECK-SPIRV-14:ConvertPtrToU
42-
// CHECK-SPIRV-14:ULessThan

llvm-spirv/test/complex-constexpr.ll

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
; RUN: llvm-as %s -o %t.bc
2-
; RUN: llvm-spirv %t.bc --spirv-max-version=1.3 -o %t.spv
3-
; RUN: spirv-val %t.spv
4-
; RUN: llvm-spirv %t.spv --spirv-max-version=1.3 -o %t.spt --to-text
5-
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6-
; RUN: llvm-dis %t.rev.bc
7-
; RUN: FileCheck %s --input-file %t.spt -check-prefix=CHECK-SPIRV
8-
; RUN: FileCheck %s --input-file %t.rev.ll -check-prefix=CHECK-LLVM
9-
102
; RUN: llvm-spirv %t.bc -o %t.spv
11-
; RUN: spirv-val %t.spv
123
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
13-
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
14-
; RUN: llvm-dis %t.rev.bc
15-
; RUN: FileCheck %s --input-file %t.spt -check-prefix=CHECK-SPIRV-14
16-
; RUN: FileCheck %s --input-file %t.rev.ll -check-prefix=CHECK-LLVM-14
17-
4+
; RUN: llvm-spirv -r %t.spv -o %t.bc
5+
; RUN: llvm-dis %t.bc -o %t.ll
6+
; RUN: FileCheck %s --input-file %t.spt -check-prefix=CHECK-SPIRV
7+
; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-LLVM
8+
; RUN: spirv-val %t.spv
189

1910
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
2011
target triple = "spir64"
@@ -25,12 +16,6 @@ target triple = "spir64"
2516
; CHECK-SPIRV: TypePointer [[Ptr_Ty:[0-9]+]] 8
2617
; CHECK-SPIRV: TypeFunction [[Func_Ty2:[0-9]+]] [[Void_Ty]] [[Ptr_Ty]] [[Ptr_Ty]]
2718

28-
; CHECK-SPIRV-14: TypeInt [[Int_Ty:[0-9]+]] 8 0
29-
; CHECK-SPIRV-14: TypeVoid [[Void_Ty:[0-9]+]]
30-
; CHECK-SPIRV-14: TypeFunction [[Func_Ty1:[0-9]+]] [[Void_Ty]]
31-
; CHECK-SPIRV-14: TypePointer [[Ptr_Ty:[0-9]+]] 8
32-
; CHECK-SPIRV-14: TypeFunction [[Func_Ty2:[0-9]+]] [[Void_Ty]] [[Ptr_Ty]] [[Ptr_Ty]]
33-
3419
@.str.1 = private unnamed_addr addrspace(1) constant [1 x i8] zeroinitializer, align 1
3520

3621
define linkonce_odr hidden spir_func void @foo() {
@@ -42,28 +27,13 @@ entry:
4227
; CHECK-SPIRV: ConvertUToPtr {{[0-9]+}} [[UToPtr:[0-9]+]]
4328
; CHECK-SPIRV: Select {{[0-9]+}} [[Sel:[0-9]+]] [[IEq]] [[UToPtr]] [[Cast]]
4429
; CHECK-SPIRV: FunctionCall [[Void_Ty]] {{[0-9]+}} [[Func:[0-9]+]] [[Cast]] [[Sel]]
45-
46-
; CHECK-SPIRV-14: PtrCastToGeneric {{[0-9]+}} [[Cast:[0-9]+]]
47-
; CHECK-SPIRV-14: PtrEqual {{[0-9]+}} [[PtrEq:[0-9]+]] [[Cast]] [[#]]
48-
; CHECK-SPIRV-14: ConvertUToPtr {{[0-9]+}} [[UToPtr:[0-9]+]]
49-
; CHECK-SPIRV-14: Select {{[0-9]+}} [[Sel:[0-9]+]] [[PtrEq]] [[UToPtr]] [[Cast]]
50-
; CHECK-SPIRV-14: FunctionCall [[Void_Ty]] {{[0-9]+}} [[Func:[0-9]+]] [[Cast]] [[Sel]]
51-
5230
; CHECK-LLVM: %[[Cast:[0-9]+]] = addrspacecast ptr addrspace(1) @.str.1 to ptr addrspace(4)
5331
; CHECK-LLVM: %[[PtrToU1:[0-9]+]] = ptrtoint ptr addrspace(4) %[[Cast]] to i64
5432
; CHECK-LLVM: %[[PtrToU2:[0-9]+]] = ptrtoint ptr addrspace(4) null to i64
5533
; CHECK-LLVM: %[[IEq:[0-9]+]] = icmp eq i64 %[[PtrToU1]], %[[PtrToU2]]
5634
; CHECK-LLVM: %[[UToPtr:[0-9]+]] = inttoptr i64 -1 to ptr addrspace(4)
5735
; CHECK-LLVM: %[[Sel:[0-9]+]] = select i1 %[[IEq]], ptr addrspace(4) %[[UToPtr]], ptr addrspace(4) %[[Cast]]
5836
; CHECK-LLVM: call spir_func void @bar(ptr addrspace(4) %[[Cast]], ptr addrspace(4) %[[Sel]]) #0
59-
60-
; CHECK-LLVM-14: %[[Cast:[0-9]+]] = addrspacecast ptr addrspace(1) @.str.1 to ptr addrspace(4)
61-
; CHECK-LLVM-14: %[[PtrToU1:[0-9]+]] = ptrtoint ptr addrspace(4) %[[Cast]] to i64
62-
; CHECK-LLVM-14: %[[IEq:[0-9]+]] = icmp eq i64 %[[PtrToU1]], 0
63-
; CHECK-LLVM-14: %[[UToPtr:[0-9]+]] = inttoptr i64 -1 to ptr addrspace(4)
64-
; CHECK-LLVM-14: %[[Sel:[0-9]+]] = select i1 %[[IEq]], ptr addrspace(4) %[[UToPtr]], ptr addrspace(4) %[[Cast]]
65-
; CHECK-LLVM-14: call spir_func void @bar(ptr addrspace(4) %[[Cast]], ptr addrspace(4) %[[Sel]]) #0
66-
6737
%0 = select i1 icmp eq (ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str.1 to ptr addrspace(4)), ptr addrspace(4) null), ptr addrspace(4) inttoptr (i64 -1 to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str.1 to ptr addrspace(4))
6838
call spir_func void @bar(ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str.1 to ptr addrspace(4)), ptr addrspace(4) %0)
6939
ret void

llvm-spirv/test/type-scavenger/ptr-abuse.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ define spir_kernel void @foo() {
2222
; CHECK: 4 Bitcast [[FLOATPTR]] [[STOREB:[0-9]+]] [[IPTR]]
2323
; CHECK: Store [[STOREB]] {{[0-9]+}}
2424
; CHECK: 4 Bitcast [[INTPTR]] [[CMPB:[0-9]+]] [[FPTR]]
25-
; CHECK: 5 PtrEqual [[#]] [[#]] [[IPTR]] [[CMPB]]
25+
; CHECK: 4 ConvertPtrToU [[SIZET:[0-9]+]] [[CMPL:[0-9]+]] [[IPTR]]
26+
; CHECK: 4 ConvertPtrToU [[SIZET]] [[CMPR:[0-9]+]] [[CMPB]]
27+
; CHECK: 5 IEqual {{[0-9]+}} {{[0-9]+}} [[CMPL]] [[CMPR]]
2628
entry:
2729
%iptr = alloca i32, align 4
2830
%fptr = alloca float, align 4

0 commit comments

Comments
 (0)