[PATCH] D107872: [SimplifyLibCalls] propagate tail flag on FORITIFY calls

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 16:33:14 PDT 2021


nickdesaulniers created this revision.
nickdesaulniers added reviewers: t.p.northover, george.burgess.iv.
Herald added a subscriber: hiraditya.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I noticed we weren't propagating tail flags on calls when
FortifiedLibCallSimplifier.optimizeCall() was replacing calls to runtime
checked calls to the non-checked routines (when safe to do so). Make
sure to check this before replacing the original calls!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107872

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/fortify-folding.ll


Index: llvm/test/Transforms/InstCombine/fortify-folding.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fortify-folding.ll
+++ llvm/test/Transforms/InstCombine/fortify-folding.ll
@@ -11,12 +11,12 @@
 
 define i8* @test_memccpy() {
 ; CHECK-LABEL: @test_memccpy(
-; CHECK-NEXT:    [[MEMCCPY:%.*]] = call i8* @memccpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i32 0, i64 60)
+; CHECK-NEXT:    [[MEMCCPY:%.*]] = tail call i8* @memccpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i32 0, i64 60)
 ; CHECK-NEXT:    ret i8* [[MEMCCPY]]
 ;
   %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
   %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
-  %ret = call i8* @__memccpy_chk(i8* %dst, i8* %src, i32 0, i64 60, i64 -1)
+  %ret = tail call i8* @__memccpy_chk(i8* %dst, i8* %src, i32 0, i64 60, i64 -1)
   ret i8* %ret
 }
 
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3036,6 +3036,10 @@
     // Try to further simplify the result.
     CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
     if (SimplifiedCI && SimplifiedCI->getCalledFunction()) {
+
+      if (CI->isTailCall() && !SimplifiedCI->isTailCall())
+        SimplifiedCI->setTailCall();
+
       // Ensure that SimplifiedCI's uses are complete, since some calls have
       // their uses analyzed.
       replaceAllUsesWith(CI, SimplifiedCI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107872.365626.patch
Type: text/x-patch
Size: 1788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210810/7f5fb1ca/attachment.bin>


More information about the llvm-commits mailing list