[llvm] [CGP] Undo constant propagation of pointers across calls (PR #102926)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 06:09:58 PDT 2024
================
@@ -0,0 +1,123 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s
+
+%struct.S = type { i8 }
+%struct.X = type { i32 }
+
+ at g_getS = internal global %struct.S zeroinitializer, align 1
+ at g_getX = internal global %struct.X zeroinitializer, align 1
+ at guard = internal global i64 0, align 8
+
+declare ptr @getS_dec()
+
+define nonnull align 1 dereferenceable(1) ptr @getS() personality ptr @__gxx_personality_v0 {
+entry:
+ %guard = load atomic i8, ptr @guard acquire, align 8
+ %mask = and i8 %guard, 1
+ %cond = icmp eq i8 %mask, 0
+ br i1 %cond, label %to_be_init, label %return
+
+to_be_init: ; preds = %entry
+ %is_init = call i32 @__cxa_guard_acquire(ptr @guard)
+ %cond.2 = icmp ne i32 %is_init, 0
+ br i1 %cond.2, label %ctor, label %return
+
+ctor: ; preds = %to_be_init
+ invoke void @S_ctor(ptr nonnull align 1 dereferenceable(1) @g_getS)
+ to label %continue unwind label %landing_pad
+
+continue: ; preds = %ctor
+ call void @__cxa_guard_release(ptr @guard)
+ br label %return
+
+return: ; preds = %continue, %to_be_init, %entry
+ ret ptr @g_getS
+
+landing_pad: ; preds = %ctor
+ %lp = landingpad { ptr, i32 } cleanup
+ call void @__cxa_guard_abort(ptr @guard)
+ resume { ptr, i32 } %lp
+}
+
+define ptr @getS_or_getX(i1 %cond) {
+entry:
+ %result = select i1 %cond, ptr @g_getS, ptr @g_getX
+ ret ptr %result
+}
+
+define weak ptr @getS_weak_function() {
+entry:
+ ret ptr @g_getS
+}
+
+define available_externally dllimport ptr @getS_dllimport_function() {
+entry:
+ ret ptr @g_getS
+}
+
+; May revert propagation.
+define i32 @caller_1() {
+; CHECK-LABEL: @caller_1(
+; CHECK-NEXT: [[GETS_PTR:%.*]] = call nonnull align 1 dereferenceable(1) ptr @getS()
+; CHECK-NEXT: [[GETI:%.*]] = call i32 @S_getI(ptr nonnull align 1 dereferenceable(1) [[GETS_PTR]])
+; CHECK-NEXT: ret i32 [[GETI]]
+;
+ %getS_ptr = call nonnull align 1 dereferenceable(1) ptr @getS()
----------------
nikic wrote:
Remove unnecessary attributes here and elsewhere.
https://github.com/llvm/llvm-project/pull/102926
More information about the llvm-commits
mailing list