Skip to content

Commit 1ad0ade

Browse files
jrtc27veselypeta
authored andcommitted
[clang][IR] Overload @llvm.thread.pointer to support non-AS0 targets
2 parents 5f0a361 + d41360b commit 1ad0ade

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,8 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
13361336

13371337
case 't':
13381338
if (Name == "thread.pointer") {
1339-
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::thread_pointer,
1340-
F->getReturnType());
1339+
NewFn = Intrinsic::getDeclaration(
1340+
F->getParent(), Intrinsic::thread_pointer, F->getReturnType());
13411341
return true;
13421342
}
13431343
break;

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17981,12 +17981,14 @@ bool RISCVTargetLowering::preferScalarizeSplat(SDNode *N) const {
1798117981

1798217982
static Value *useTpOffset(IRBuilderBase &IRB, unsigned Offset) {
1798317983
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
17984-
Function *ThreadPointerFunc = Intrinsic::getDeclaration(
17985-
M, Intrinsic::thread_pointer, IRB.getInt8PtrTy());
17984+
unsigned AS = M->getDataLayout().getGlobalsAddressSpace();
17985+
Function *ThreadPointerFunc =
17986+
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer,
17987+
IRB.getInt8PtrTy(AS));
1798617988
return IRB.CreatePointerCast(
1798717989
IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
1798817990
IRB.CreateCall(ThreadPointerFunc), Offset),
17989-
IRB.getInt8PtrTy()->getPointerTo(0));
17991+
IRB.getInt8PtrTy()->getPointerTo(AS));
1799017992
}
1799117993

1799217994
Value *RISCVTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {

llvm/test/Assembler/autoupgrade-thread-pointer.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare ptr @llvm.arm.thread.pointer()
77
define ptr @test1() {
88
; CHECK: test1()
99
; CHECK: call ptr @llvm.thread.pointer.p0()
10-
%1 = call i8* @llvm.aarch64.thread.pointer()
10+
%1 = call ptr @llvm.aarch64.thread.pointer()
1111
ret ptr %1
1212
}
1313

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: %riscv32_cheri_purecap_llc < %s | FileCheck %s
3+
; RUN: %riscv64_cheri_purecap_llc < %s | FileCheck %s
4+
5+
declare ptr addrspace(200) @llvm.thread.pointer.p200()
6+
7+
define ptr addrspace(200) @thread_pointer() nounwind {
8+
; CHECK-LABEL: thread_pointer:
9+
; CHECK: # %bb.0:
10+
; CHECK-NEXT: cmove ca0, ctp
11+
; CHECK-NEXT: ret
12+
%1 = tail call ptr addrspace(200) @llvm.thread.pointer.p200()
13+
ret ptr addrspace(200) %1
14+
}

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,10 @@ TEST(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
11751175
// Test for a call to a function without side-effects.
11761176
LLVMContext C;
11771177
Module M("", C);
1178+
IntegerType *Int8 = IntegerType::get(C, 8);
1179+
PointerType *Int8Ptr = PointerType::get(Int8, 0);
11781180
Function *TheFn = Intrinsic::getDeclaration(&M, Intrinsic::thread_pointer,
1179-
llvm::PointerType::get(C, 0));
1181+
Int8Ptr);
11801182

11811183
auto *Call = CallInst::Create(TheFn->getFunctionType(), TheFn);
11821184
VPValue Op1;

0 commit comments

Comments
 (0)