Skip to content
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

[InstCombine] Fix removal of adjacent tapir.runtime.start and tapir.r… #212

Merged
merged 1 commit into from
Oct 21, 2023
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: 2 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,8 +2440,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
BasicBlock::iterator Iter(CI);
while (++Iter != CI.getParent()->end()) {
if (isTapirIntrinsic(Intrinsic::tapir_runtime_end, &*Iter, &CI)) {
eraseInstFromFunction(CI);
return eraseInstFromFunction(*Iter);
eraseInstFromFunction(*Iter);
return eraseInstFromFunction(CI);
}
if (isa<CallBase>(&*Iter) && !isa<DbgInfoIntrinsic>(&*Iter))
// We found a nontrivial call. Give up.
Expand Down
49 changes: 49 additions & 0 deletions llvm/test/Transforms/Tapir/empty-scope.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
; Check that instcombine properly removes adjacent tapir.runtime
; calls.
;
; RUN: opt < %s -passes="instcombine" -S | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %argc, ptr noundef %argv) #0 {
entry:
%retval = alloca i32, align 4
%argc.addr = alloca i32, align 4
%argv.addr = alloca ptr, align 8
store i32 0, ptr %retval, align 4
store i32 %argc, ptr %argc.addr, align 4, !tbaa !5
store ptr %argv, ptr %argv.addr, align 8, !tbaa !9
%0 = call token @llvm.tapir.runtime.start()
call void @llvm.tapir.runtime.end(token %0)
ret i32 0
}

; CHECK: define {{.*}}i32 @main(
; CHECK-NOT: call token @llvm.tapir.runtime.start
; CHECK-NOT: call void @llvm.tapir.runtime.end
; CHECK: ret

; Function Attrs: nounwind willreturn memory(argmem: readwrite)
declare token @llvm.tapir.runtime.start() #1

; Function Attrs: nounwind willreturn memory(argmem: readwrite)
declare void @llvm.tapir.runtime.end(token) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind willreturn memory(argmem: readwrite) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 16.0.6 ([email protected]:OpenCilk/opencilk-project.git ca9e0f93cdcefe84809f3ddd9c61363b76a1a271)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}