[llvm] [CGP] Consider arguments and ret values in `dupRetToEnableTailCallOpts` (PR #76613)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 30 13:55:50 PST 2024
================
@@ -184,3 +184,126 @@ return:
%retval = phi ptr [ %ptr, %if.then ], [ %obj, %entry ]
ret ptr %retval
}
+
+define ptr @memset_tailc(ptr %ret_val, i64 %sz) {
+; CHECK-LABEL: memset_tailc:
+; CHECK: ## %bb.0: ## %entry
+; CHECK: testq %rdi, %rdi
+; CHECK: je LBB4_1
+; CHECK: ## %bb.2: ## %if.then
+; CHECK: movq %rsi, %rdx
+; CHECK: xorl %esi, %esi
+; CHECK: jmp _memset ## TAILCALL
+; CHECK: LBB4_1: ## %return
+; CHECK: movq %rdi, %rax
+; CHECK: retq
+entry:
+ %cmp = icmp eq ptr %ret_val, null
+ br i1 %cmp, label %return, label %if.then
+
+if.then:
+ tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %ret_val, i8 0, i64 %sz, i1 false)
+ br label %return
+
+return:
+ ret ptr %ret_val
+}
+
+define ptr @memcpy_tailc(ptr %ret_val, i64 %sz, ptr %src) {
+; CHECK-LABEL: memcpy_tailc:
+; CHECK: ## %bb.0: ## %entry
+; CHECK: testq %rsi, %rsi
+; CHECK: je LBB5_1
+; CHECK: ## %bb.2: ## %if.then
+; CHECK: movq %rsi, %rax
+; CHECK: movq %rdx, %rsi
+; CHECK: movq %rax, %rdx
+; CHECK: jmp _memcpy ## TAILCALL
+; CHECK: LBB5_1: ## %return
+; CHECK: movq %rdx, %rax
+; CHECK: retq
+entry:
+ %cmp = icmp eq i64 %sz, 0
+ br i1 %cmp, label %return, label %if.then
+
+if.then:
+ tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %ret_val, ptr align 1 %src, i64 %sz, i1 false)
+ br label %return
+
+return:
+ %phi = phi ptr [ %ret_val, %if.then ], [ %src, %entry ]
+ ret ptr %phi
+}
+
+define ptr @strcpy_tailc(i64 %0, ptr %src) {
----------------
antoniofrighetto wrote:
Added https://clang.godbolt.org/z/a3rns4883, thanks.
https://github.com/llvm/llvm-project/pull/76613
More information about the llvm-commits
mailing list