From 20bc09ebd3ae500f2fd044a2858d97eab19c533b Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 13 Jan 2022 09:49:03 -0500 Subject: [PATCH] Handle freeze instruction in FindBaseValue (#43728) --- src/llvm-late-gc-lowering.cpp | 2 ++ test/llvmpasses/late-lower-gc.ll | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index 2842b964a45a71..81331e43a7fe47 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -469,6 +469,8 @@ static std::pair FindBaseValue(const State &S, Value *V, bool UseCac if (getValueAddrSpace(NewV) == 0) break; CurrentV = NewV; + } else if (auto *Freeze = dyn_cast(CurrentV)) { + CurrentV = Freeze->getOperand(0); // Can be formed by optimizations, treat as a no-op } else if (auto *GEP = dyn_cast(CurrentV)) { CurrentV = GEP->getOperand(0); // GEP can make vectors from a single base pointer diff --git a/test/llvmpasses/late-lower-gc.ll b/test/llvmpasses/late-lower-gc.ll index 441fce2bbac08e..22cb558c54158b 100644 --- a/test/llvmpasses/late-lower-gc.ll +++ b/test/llvmpasses/late-lower-gc.ll @@ -105,6 +105,25 @@ top: ; CHECK: ret i32 } +define i32 @freeze({} addrspace(10)* %v0, {} addrspace(10)* %v1) { +top: +; CHECK-LABEL: @freeze +; CHECK-NOT: @julia.new_gc_frame + %v2 = call {}*** @julia.get_pgcstack() + %v3 = bitcast {} addrspace(10)* %v0 to {} addrspace(10)* addrspace(10)* + %v4 = addrspacecast {} addrspace(10)* addrspace(10)* %v3 to {} addrspace(10)* addrspace(11)* + %v5 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %v4 unordered, align 8 + %v6 = bitcast {} addrspace(10)* %v1 to {} addrspace(10)* addrspace(10)* + %v7 = addrspacecast {} addrspace(10)* addrspace(10)* %v6 to {} addrspace(10)* addrspace(11)* + %v8 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %v7 unordered, align 8 + %fv8 = freeze {} addrspace(10)* %v8 + %v9 = addrspacecast {} addrspace(10)* %v5 to {} addrspace(12)* + %v10 = addrspacecast {} addrspace(10)* %fv8 to {} addrspace(12)* + %v11 = call i32 @rooting_callee({} addrspace(12)* %v9, {} addrspace(12)* %v10) + ret i32 %v11 +; CHECK: ret i32 +} + !0 = !{i64 0, i64 23} !1 = !{} !2 = distinct !{!2}