Skip to content

Commit 6710b21

Browse files
author
Kai Luo
committed
[PowerPC] Allow llvm.ppc.cfence to accept pointer types
In the context of atomic load, integer, pointer and float point types are allowed, thus we should allow llvm.ppc.cfence to accept any type mentioned. Fixes #55983. Reviewed By: shchenz, vchuravy Differential Revision: https://reviews.llvm.org/D127554
1 parent 770fe86 commit 6710b21

File tree

7 files changed

+103
-13
lines changed

7 files changed

+103
-13
lines changed

llvm/include/llvm/IR/IntrinsicsPowerPC.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,11 @@ def int_ppc_tsuspend : ClangBuiltin<"__builtin_tsuspend">,
14931493
def int_ppc_ttest : ClangBuiltin<"__builtin_ttest">,
14941494
Intrinsic<[llvm_i64_ty], [], []>;
14951495

1496-
def int_ppc_cfence : Intrinsic<[], [llvm_anyint_ty], []>;
1496+
// We currently use llvm.ppc.cfence in the context of atomic load which
1497+
// in LLVM IR requires its type to be one of integer, pointer and
1498+
// float point type. So llvm_any_ty here refers to type mentioned above.
1499+
// Backend is supposed to lower these types to appropriate MVTs.
1500+
def int_ppc_cfence : Intrinsic<[], [llvm_any_ty], []>;
14971501

14981502
// PowerPC set FPSCR Intrinsic Definitions.
14991503
def int_ppc_setrnd : ClangBuiltin<"__builtin_setrnd">,

llvm/test/CodeGen/PowerPC/cfence-double.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
; REQUIRES: asserts
12
; RUN: not --crash llc -opaque-pointers -mtriple=powerpc64le-unknown-unknown \
23
; RUN: < %s 2>&1 | FileCheck %s
34
; RUN: not --crash llc -opaque-pointers -mtriple=powerpc64-unknown-unknown \
45
; RUN: < %s 2>&1 | FileCheck %s
56

6-
; CHECK: Intrinsic has incorrect argument type!
7-
; CHECK: ptr @llvm.ppc.cfence.f64
7+
; CHECK: Assertion `VT.isInteger() && Operand.getValueType().isInteger() && "Invalid ANY_EXTEND!"' failed
8+
89
define double @foo(double* %dp) {
910
entry:
1011
%0 = load atomic double, double* %dp acquire, align 8

llvm/test/CodeGen/PowerPC/cfence-float.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
; REQUIRES: asserts
12
; RUN: not --crash llc -opaque-pointers -mtriple=powerpc64le-unknown-unknown \
23
; RUN: < %s 2>&1 | FileCheck %s
34
; RUN: not --crash llc -opaque-pointers -mtriple=powerpc64-unknown-unknown \
45
; RUN: < %s 2>&1 | FileCheck %s
56

6-
; CHECK: Intrinsic has incorrect argument type!
7-
; CHECK: ptr @llvm.ppc.cfence.f32
7+
; CHECK: Assertion `VT.isInteger() && Operand.getValueType().isInteger() && "Invalid ANY_EXTEND!"' failed
8+
89
define float @bar(float* %fp) {
910
entry:
1011
%0 = load atomic float, float* %fp acquire, align 4
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -opaque-pointers -mtriple=powerpc64le-unknown-unknown < %s | FileCheck --check-prefix=CHECK-LE %s
3+
; RUN: llc -opaque-pointers -mtriple=powerpc64-unknown-unknown < %s | FileCheck %s
4+
5+
define ptr @foo(ptr %p) {
6+
; CHECK-LE-LABEL: foo:
7+
; CHECK-LE: # %bb.0: # %entry
8+
; CHECK-LE-NEXT: ld 3, 0(3)
9+
; CHECK-LE-NEXT: cmpd 7, 3, 3
10+
; CHECK-LE-NEXT: bne- 7, .+4
11+
; CHECK-LE-NEXT: isync
12+
; CHECK-LE-NEXT: blr
13+
;
14+
; CHECK-LABEL: foo:
15+
; CHECK: # %bb.0: # %entry
16+
; CHECK-NEXT: ld 3, 0(3)
17+
; CHECK-NEXT: cmpd 7, 3, 3
18+
; CHECK-NEXT: bne- 7, .+4
19+
; CHECK-NEXT: isync
20+
; CHECK-NEXT: blr
21+
entry:
22+
%0 = load atomic ptr, ptr %p acquire, align 8
23+
ret ptr %0
24+
}
25+
26+
define void @foobar({} addrspace(10)* addrspace(11)* %p) {
27+
; CHECK-LE-LABEL: foobar:
28+
; CHECK-LE: # %bb.0: # %entry
29+
; CHECK-LE-NEXT: ld 3, 0(3)
30+
; CHECK-LE-NEXT: cmpd 7, 3, 3
31+
; CHECK-LE-NEXT: bne- 7, .+4
32+
; CHECK-LE-NEXT: isync
33+
;
34+
; CHECK-LABEL: foobar:
35+
; CHECK: # %bb.0: # %entry
36+
; CHECK-NEXT: ld 3, 0(3)
37+
; CHECK-NEXT: cmpd 7, 3, 3
38+
; CHECK-NEXT: bne- 7, .+4
39+
; CHECK-NEXT: isync
40+
entry:
41+
%0 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %p acquire, align 8
42+
unreachable
43+
}

llvm/test/Transforms/AtomicExpand/PowerPC/cfence-double.ll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
; RUN: not --crash opt -S -atomic-expand -mtriple=powerpc64le-unknown-unknown \
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -atomic-expand -mtriple=powerpc64le-unknown-unknown \
23
; RUN: -opaque-pointers < %s 2>&1 | FileCheck %s
3-
; RUN: not --crash opt -S -atomic-expand -mtriple=powerpc64-unknown-unknown \
4+
; RUN: opt -S -atomic-expand -mtriple=powerpc64-unknown-unknown \
45
; RUN: -opaque-pointers < %s 2>&1 | FileCheck %s
56

6-
; CHECK: Intrinsic has incorrect argument type!
7-
; CHECK: ptr @llvm.ppc.cfence.f64
87
define double @foo(double* %dp) {
8+
; CHECK-LABEL: @foo(
9+
; CHECK-NEXT: entry:
10+
; CHECK-NEXT: [[TMP0:%.*]] = load atomic i64, ptr [[DP:%.*]] monotonic, align 8
11+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i64 [[TMP0]] to double
12+
; CHECK-NEXT: call void @llvm.ppc.cfence.f64(double [[TMP1]])
13+
; CHECK-NEXT: ret double [[TMP1]]
14+
;
915
entry:
1016
%0 = load atomic double, double* %dp acquire, align 8
1117
ret double %0

llvm/test/Transforms/AtomicExpand/PowerPC/cfence-float.ll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
; RUN: not --crash opt -S -atomic-expand -mtriple=powerpc64le-unknown-unknown \
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -atomic-expand -mtriple=powerpc64le-unknown-unknown \
23
; RUN: -opaque-pointers < %s 2>&1 | FileCheck %s
3-
; RUN: not --crash opt -S -atomic-expand -mtriple=powerpc64-unknown-unknown \
4+
; RUN: opt -S -atomic-expand -mtriple=powerpc64-unknown-unknown \
45
; RUN: -opaque-pointers < %s 2>&1 | FileCheck %s
56

6-
; CHECK: Intrinsic has incorrect argument type!
7-
; CHECK: ptr @llvm.ppc.cfence.f32
87
define float @bar(float* %fp) {
8+
; CHECK-LABEL: @bar(
9+
; CHECK-NEXT: entry:
10+
; CHECK-NEXT: [[TMP0:%.*]] = load atomic i32, ptr [[FP:%.*]] monotonic, align 4
11+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 [[TMP0]] to float
12+
; CHECK-NEXT: call void @llvm.ppc.cfence.f32(float [[TMP1]])
13+
; CHECK-NEXT: ret float [[TMP1]]
14+
;
915
entry:
1016
%0 = load atomic float, float* %fp acquire, align 4
1117
ret float %0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -opaque-pointers -atomic-expand -S -mtriple=powerpc64le-unknown-unknown \
3+
; RUN: %s | FileCheck %s
4+
; RUN: opt -opaque-pointers -atomic-expand -S -mtriple=powerpc64-unknown-unknown \
5+
; RUN: %s | FileCheck %s
6+
7+
define ptr @foo(ptr %p) {
8+
; CHECK-LABEL: @foo(
9+
; CHECK-NEXT: entry:
10+
; CHECK-NEXT: [[TMP0:%.*]] = load atomic ptr, ptr [[P:%.*]] monotonic, align 8
11+
; CHECK-NEXT: call void @llvm.ppc.cfence.p0(ptr [[TMP0]])
12+
; CHECK-NEXT: ret ptr [[TMP0]]
13+
;
14+
entry:
15+
%0 = load atomic ptr, ptr %p acquire, align 8
16+
ret ptr %0
17+
}
18+
19+
define void @foobar({} addrspace(10)* addrspace(11)* %p) {
20+
; CHECK-LABEL: @foobar(
21+
; CHECK-NEXT: entry:
22+
; CHECK-NEXT: [[TMP0:%.*]] = load atomic ptr addrspace(10), ptr addrspace(11) [[P:%.*]] monotonic, align 8
23+
; CHECK-NEXT: call void @llvm.ppc.cfence.p10(ptr addrspace(10) [[TMP0]])
24+
; CHECK-NEXT: unreachable
25+
;
26+
entry:
27+
%0 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %p acquire, align 8
28+
unreachable
29+
}

0 commit comments

Comments
 (0)