From 5e3d770fccd3639773b69bdd8671a03fd80e3dc1 Mon Sep 17 00:00:00 2001 From: TB Schardl Date: Fri, 20 Oct 2023 00:15:22 +0000 Subject: [PATCH] [InstCombine] Fix removal of adjacent tapir.runtime.start and tapir.runtime.end calls. --- .../InstCombine/InstCombineCalls.cpp | 4 +- llvm/test/Transforms/Tapir/empty-scope.ll | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Transforms/Tapir/empty-scope.ll diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 9df30997b243..3a9de1321d23 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -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(&*Iter) && !isa(&*Iter)) // We found a nontrivial call. Give up. diff --git a/llvm/test/Transforms/Tapir/empty-scope.ll b/llvm/test/Transforms/Tapir/empty-scope.ll new file mode 100644 index 000000000000..ae7117b00e55 --- /dev/null +++ b/llvm/test/Transforms/Tapir/empty-scope.ll @@ -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 (git@github.com: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}