Skip to content

Commit 832547f

Browse files
andjo403AlexisPerry
authored andcommitted
[Clang] Swap range and noundef metadata to attribute for intrinsics. (llvm#94851)
1 parent c134696 commit 832547f

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,14 @@ static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF,
734734
return CGF.Builder.CreateExtractValue(Tmp, 0);
735735
}
736736

737-
static Value *emitRangedBuiltin(CodeGenFunction &CGF,
738-
unsigned IntrinsicID,
737+
static Value *emitRangedBuiltin(CodeGenFunction &CGF, unsigned IntrinsicID,
739738
int low, int high) {
740-
llvm::MDBuilder MDHelper(CGF.getLLVMContext());
741-
llvm::MDNode *RNode = MDHelper.createRange(APInt(32, low), APInt(32, high));
742-
Function *F = CGF.CGM.getIntrinsic(IntrinsicID, {});
743-
llvm::Instruction *Call = CGF.Builder.CreateCall(F);
744-
Call->setMetadata(llvm::LLVMContext::MD_range, RNode);
745-
Call->setMetadata(llvm::LLVMContext::MD_noundef,
746-
llvm::MDNode::get(CGF.getLLVMContext(), std::nullopt));
747-
return Call;
739+
Function *F = CGF.CGM.getIntrinsic(IntrinsicID, {});
740+
llvm::CallInst *Call = CGF.Builder.CreateCall(F);
741+
llvm::ConstantRange CR(APInt(32, low), APInt(32, high));
742+
Call->addRangeRetAttr(CR);
743+
Call->addRetAttr(llvm::Attribute::AttrKind::NoUndef);
744+
return Call;
748745
}
749746

750747
namespace {

clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ void test_s_getreg(volatile global uint *out)
605605
}
606606

607607
// CHECK-LABEL: @test_get_local_id(
608-
// CHECK: tail call{{.*}} i32 @llvm.amdgcn.workitem.id.x(), !range [[$WI_RANGE:![0-9]*]], !noundef
609-
// CHECK: tail call{{.*}} i32 @llvm.amdgcn.workitem.id.y(), !range [[$WI_RANGE]], !noundef
610-
// CHECK: tail call{{.*}} i32 @llvm.amdgcn.workitem.id.z(), !range [[$WI_RANGE]], !noundef
608+
// CHECK: tail call noundef range(i32 0, 1024){{.*}} i32 @llvm.amdgcn.workitem.id.x()
609+
// CHECK: tail call noundef range(i32 0, 1024){{.*}} i32 @llvm.amdgcn.workitem.id.y()
610+
// CHECK: tail call noundef range(i32 0, 1024){{.*}} i32 @llvm.amdgcn.workitem.id.z()
611611
void test_get_local_id(int d, global int *out)
612612
{
613613
switch (d) {
@@ -891,6 +891,5 @@ void test_set_fpenv(unsigned long env) {
891891
__builtin_amdgcn_set_fpenv(env);
892892
}
893893

894-
// CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
895894
// CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
896895
// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { convergent mustprogress nocallback nofree nounwind willreturn memory(none) }

clang/test/CodeGenOpenCL/builtins-r600.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void test_get_group_id(int d, global int *out)
3939
}
4040

4141
// CHECK-LABEL: @test_get_local_id(
42-
// CHECK: tail call i32 @llvm.r600.read.tidig.x(), !range [[WI_RANGE:![0-9]*]]
43-
// CHECK: tail call i32 @llvm.r600.read.tidig.y(), !range [[WI_RANGE]]
44-
// CHECK: tail call i32 @llvm.r600.read.tidig.z(), !range [[WI_RANGE]]
42+
// CHECK: tail call noundef range(i32 0, 1024) i32 @llvm.r600.read.tidig.x()
43+
// CHECK: tail call noundef range(i32 0, 1024) i32 @llvm.r600.read.tidig.y()
44+
// CHECK: tail call noundef range(i32 0, 1024) i32 @llvm.r600.read.tidig.z()
4545
void test_get_local_id(int d, global int *out)
4646
{
4747
switch (d) {
@@ -52,4 +52,3 @@ void test_get_local_id(int d, global int *out)
5252
}
5353
}
5454

55-
// CHECK-DAG: [[WI_RANGE]] = !{i32 0, i32 1024}

0 commit comments

Comments
 (0)