Skip to content

Commit

Permalink
[InstCombine] Fix removal of adjacent tapir.runtime.start and tapir.r…
Browse files Browse the repository at this point in the history
…untime.end calls.
  • Loading branch information
neboat committed Oct 21, 2023
1 parent 7efc4dd commit 5e3d770
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
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}

0 comments on commit 5e3d770

Please sign in to comment.