[PATCH] D22243: [PPC] Handling CallInst in PPCBoolRetToInt

Guozhi Wei via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 16:08:47 PDT 2016


Carrot created this revision.
Carrot added a reviewer: hfinkel.
Carrot added a subscriber: llvm-commits.
Herald added a subscriber: nemanjai.

This patch fixes pr25548.

Current implementation of PPCBoolRetToInt doesn't handle CallInst correctly, so it failed to do the intended optimization when there is a CallInst with parameters. This patch fixed that.

http://reviews.llvm.org/D22243

Files:
  lib/Target/PowerPC/PPCBoolRetToInt.cpp
  test/CodeGen/PowerPC/BoolRetToIntTest.ll

Index: test/CodeGen/PowerPC/BoolRetToIntTest.ll
===================================================================
--- test/CodeGen/PowerPC/BoolRetToIntTest.ll
+++ test/CodeGen/PowerPC/BoolRetToIntTest.ll
@@ -198,6 +198,8 @@
 define zeroext i1 @call_test() {
 ; CHECK: [[REG:%.+]] = call i1
   %result = call i1 @return_i1()
+; CHECK: [[REG:%.+]] = zext i1 {{%.+}} to i32
+; CHECK: [[REG:%.+]] = trunc i32 {{%.+}} to i1
 ; CHECK: ret i1 [[REG]]
   ret i1 %result
-}
\ No newline at end of file
+}
Index: lib/Target/PowerPC/PPCBoolRetToInt.cpp
===================================================================
--- lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -66,7 +66,8 @@
     while (!WorkList.empty()) {
       Value *Curr = WorkList.back();
       WorkList.pop_back();
-      if (User *CurrUser = dyn_cast<User>(Curr))
+      User *CurrUser = dyn_cast<User>(Curr);
+      if (CurrUser && !isa<CallInst>(Curr))
         for (auto &Op : CurrUser->operands())
           if (Defs.insert(Op).second)
             WorkList.push_back(Op);
@@ -199,11 +200,12 @@
     if (!std::any_of(Defs.begin(), Defs.end(), isa<Instruction, Value *>))
       return false;
 
-    // Presently, we only know how to handle PHINode, Constant, and Arguments.
-    // Potentially, bitwise operations (AND, OR, XOR, NOT) and sign extension
-    // could also be handled in the future.
+    // Presently, we only know how to handle PHINode, Constant, Arguments and
+    // CallInst. Potentially, bitwise operations (AND, OR, XOR, NOT) and sign
+    // extension could also be handled in the future.
     for (Value *V : Defs)
-      if (!isa<PHINode>(V) && !isa<Constant>(V) && !isa<Argument>(V))
+      if (!isa<PHINode>(V) && !isa<Constant>(V) &&
+          !isa<Argument>(V) && !isa<CallInst>(V))
         return false;
 
     for (Value *V : Defs)
@@ -227,7 +229,7 @@
       User *First = dyn_cast<User>(Pair.first);
       User *Second = dyn_cast<User>(Pair.second);
       assert((!First || Second) && "translated from user to non-user!?");
-      if (First)
+      if (First && !isa<CallInst>(First))
         for (unsigned i = 0; i < First->getNumOperands(); ++i)
           Second->setOperand(i, BoolToIntMap[First->getOperand(i)]);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22243.63600.patch
Type: text/x-patch
Size: 2267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160711/94d1dcc1/attachment.bin>


More information about the llvm-commits mailing list