[PATCH] D60837: [CGP] Look through bitcasts when duplicating returns for tail calls

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 14:27:56 PDT 2019


thegameg updated this revision to Diff 196328.
thegameg added a comment.

- Use `Value:: stripPointerCasts` instead of checking for `BitCastInst`.
- Add `opt -codegenprepare` test and full codegen test separately (to commit before this).
- Use `utils/update_test_checks.py` and `utils/update_llc_test_checks.py` for the new tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60837/new/

https://reviews.llvm.org/D60837

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/test/CodeGen/X86/tailcall-cgp-dup.ll


Index: llvm/test/CodeGen/X86/tailcall-cgp-dup.ll
===================================================================
--- llvm/test/CodeGen/X86/tailcall-cgp-dup.ll
+++ llvm/test/CodeGen/X86/tailcall-cgp-dup.ll
@@ -118,21 +118,18 @@
 ; OPT:       if.then:
 ; OPT-NEXT:    [[PTR:%.*]] = tail call i32* @g_ret32()
 ; OPT-NEXT:    [[CASTED:%.*]] = bitcast i32* [[PTR]] to i8*
-; OPT-NEXT:    br label [[RETURN]]
+; OPT-NEXT:    ret i8* [[CASTED]]
 ; OPT:       return:
-; OPT-NEXT:    [[RETVAL:%.*]] = phi i8* [ [[CASTED]], [[IF_THEN]] ], [ [[OBJ]], [[ENTRY:%.*]] ]
-; OPT-NEXT:    ret i8* [[RETVAL]]
+; OPT-NEXT:    ret i8* [[OBJ]]
 ;
 ; CHECK-LABEL: f_ret8:
 ; CHECK:       ## %bb.0: ## %entry
-; CHECK-NEXT:    movq %rdi, %rax
 ; CHECK-NEXT:    testq %rdi, %rdi
-; CHECK-NEXT:    je LBB3_2
-; CHECK-NEXT:  ## %bb.1: ## %if.then
-; CHECK-NEXT:    pushq %rax
-; CHECK-NEXT:    callq _g_ret32
-; CHECK-NEXT:    addq $8, %rsp
-; CHECK-NEXT:  LBB3_2: ## %return
+; CHECK-NEXT:    je LBB3_1
+; CHECK-NEXT:  ## %bb.2: ## %if.then
+; CHECK-NEXT:    jmp _g_ret32 ## TAILCALL
+; CHECK-NEXT:  LBB3_1: ## %return
+; CHECK-NEXT:    movq %rdi, %rax
 ; CHECK-NEXT:    retq
 entry:
   %cmp = icmp eq i8* %obj, null
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2032,7 +2032,9 @@
   SmallVector<CallInst*, 4> TailCalls;
   if (PN) {
     for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) {
-      CallInst *CI = dyn_cast<CallInst>(PN->getIncomingValue(I));
+      // Look through bitcasts.
+      Value *IncomingVal = PN->getIncomingValue(I)->stripPointerCasts();
+      CallInst *CI = dyn_cast<CallInst>(IncomingVal);
       // Make sure the phi value is indeed produced by the tail call.
       if (CI && CI->hasOneUse() && CI->getParent() == PN->getIncomingBlock(I) &&
           TLI->mayBeEmittedAsTailCall(CI) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60837.196328.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190423/ae0c326b/attachment.bin>


More information about the llvm-commits mailing list