Skip to content

[CodeGen] Add default lowering for llvm.allow.{runtime,ubsan}.check() #86049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,8 +2462,10 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, ModifyDT &ModifiedDT) {
break;
case Intrinsic::assume:
llvm_unreachable("llvm.assume should have been removed already");
case Intrinsic::allow_runtime_check:
case Intrinsic::allow_ubsan_check:
case Intrinsic::experimental_widenable_condition: {
// Give up on future widening oppurtunties so that we can fold away dead
// Give up on future widening opportunities so that we can fold away dead
// paths and merge blocks before going into block-local instruction
// selection.
if (II->use_empty()) {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,11 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
return translateTrap(CI, MIRBuilder, TargetOpcode::G_DEBUGTRAP);
case Intrinsic::ubsantrap:
return translateTrap(CI, MIRBuilder, TargetOpcode::G_UBSANTRAP);
case Intrinsic::allow_runtime_check:
case Intrinsic::allow_ubsan_check:
MIRBuilder.buildCopy(getOrCreateVReg(CI),
getOrCreateVReg(*ConstantInt::getTrue(CI.getType())));
return true;
case Intrinsic::amdgcn_cs_chain:
return translateCallBase(CI, MIRBuilder);
case Intrinsic::fptrunc_round: {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/IntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
break;
}

case Intrinsic::allow_runtime_check:
case Intrinsic::allow_ubsan_check:
CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getType()));
return;

case Intrinsic::ctpop:
CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getArgOperand(0), CI));
break;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,10 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
case Intrinsic::is_constant:
llvm_unreachable("llvm.is.constant.* should have been lowered already");

case Intrinsic::allow_runtime_check:
case Intrinsic::allow_ubsan_check:
llvm_unreachable("llvm.*.check should have been lowered already");

case Intrinsic::launder_invariant_group:
case Intrinsic::strip_invariant_group:
case Intrinsic::expect: {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7326,6 +7326,11 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
return;
}

case Intrinsic::allow_runtime_check:
case Intrinsic::allow_ubsan_check:
setValue(&I, getValue(ConstantInt::getTrue(I.getType())));
return;

case Intrinsic::uadd_with_overflow:
case Intrinsic::sadd_with_overflow:
case Intrinsic::usub_with_overflow:
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/AArch64/allow-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=aarch64 -global-isel=1 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=1 | FileCheck %s

target triple = "aarch64-linux"

define i1 @test_runtime() local_unnamed_addr {
; CHECK-LABEL: test_runtime:
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: mov w0, #1 // =0x1
; CHECK-NEXT: ret
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test_check")
ret i1 %allow
}

declare i1 @llvm.allow.runtime.check(metadata) nounwind

define i1 @test_ubsan() local_unnamed_addr {
; CHECK-LABEL: test_ubsan:
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: mov w0, #1 // =0x1
; CHECK-NEXT: ret
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 7)
ret i1 %allow
}

declare i1 @llvm.allow.ubsan.check(i8) nounwind
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/AMDGPU/allow-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -global-isel=0 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -global-isel=1 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -global-isel=0 -fast-isel=1 | FileCheck %s

define i1 @test_runtime() local_unnamed_addr {
; CHECK-LABEL: test_runtime:
; CHECK: ; %bb.0: ; %entry
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; CHECK-NEXT: v_mov_b32_e32 v0, 1
; CHECK-NEXT: s_setpc_b64 s[30:31]
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test_check")
ret i1 %allow
}

declare i1 @llvm.allow.runtime.check(metadata) nounwind

define i1 @test_ubsan() local_unnamed_addr {
; CHECK-LABEL: test_ubsan:
; CHECK: ; %bb.0: ; %entry
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; CHECK-NEXT: v_mov_b32_e32 v0, 1
; CHECK-NEXT: s_setpc_b64 s[30:31]
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 7)
ret i1 %allow
}

declare i1 @llvm.allow.ubsan.check(i8) nounwind
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/Generic/allow-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llc < %s -O3 -global-isel=0 -fast-isel=0
; RUN: llc < %s -O3 -global-isel=1 -fast-isel=0
; RUN: llc < %s -O3 -global-isel=0 -fast-isel=1

; RUN: llc < %s -O0 -global-isel=0 -fast-isel=0
; RUN: llc < %s -O0 -global-isel=1 -fast-isel=0
; RUN: llc < %s -O0 -global-isel=0 -fast-isel=1

define i1 @test_runtime() local_unnamed_addr {
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test_check")
ret i1 %allow
}

declare i1 @llvm.allow.runtime.check(metadata) nounwind

define i1 @test_ubsan() local_unnamed_addr {
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 7)
ret i1 %allow
}

declare i1 @llvm.allow.ubsan.check(i8) nounwind
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/RISCV/allow-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=riscv32 -global-isel=0 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=riscv32 -global-isel=1 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=riscv32 -global-isel=0 -fast-isel=1 | FileCheck %s

; RUN: llc < %s -mtriple=riscv64 -global-isel=0 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=riscv64 -global-isel=1 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=riscv64 -global-isel=0 -fast-isel=1 | FileCheck %s

define i1 @test_runtime() local_unnamed_addr {
; CHECK-LABEL: test_runtime:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: li a0, 1
; CHECK-NEXT: ret
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test_check")
ret i1 %allow
}

declare i1 @llvm.allow.runtime.check(metadata) nounwind

define i1 @test_ubsan() local_unnamed_addr {
; CHECK-LABEL: test_ubsan:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: li a0, 1
; CHECK-NEXT: ret
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 7)
ret i1 %allow
}

declare i1 @llvm.allow.ubsan.check(i8) nounwind
28 changes: 28 additions & 0 deletions llvm/test/CodeGen/X86/allow-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc < %s -mtriple=x86_64 -global-isel=0 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64 -global-isel=1 -fast-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64 -global-isel=0 -fast-isel=1 | FileCheck %s

define i1 @test_runtime() local_unnamed_addr {
; CHECK-LABEL: test_runtime:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movb $1, %al
; CHECK-NEXT: retq
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test_check")
ret i1 %allow
}

declare i1 @llvm.allow.runtime.check(metadata) nounwind

define i1 @test_ubsan() local_unnamed_addr {
; CHECK-LABEL: test_ubsan:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movb $1, %al
; CHECK-NEXT: retq
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 7)
ret i1 %allow
}

declare i1 @llvm.allow.ubsan.check(i8) nounwind