[PATCH] [SimplifyCFG] Teach when it is profitable to speculate calls to @llvm.cttz/ctlz.

David Majnemer david.majnemer at gmail.com
Tue Dec 16 13:13:10 PST 2014


================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:1624-1629
@@ +1623,8 @@
+    //
+    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(ThenV)) {
+      // Don't convert this phi node into a select if 'ThenV' is a cttz/ctlz
+      // intrinsic call, but 'OrigV' is not equal to the 'size-of' in bits of
+      // the value in input to the cttz/ctlz.
+      if (II->getIntrinsicID() == Intrinsic::cttz ||
+          II->getIntrinsicID() == Intrinsic::ctlz) {
+        unsigned BitWidth = ThenV->getType()->getIntegerBitWidth();
----------------
This could be:
  if (match(ThenV, m_Intrinsic<Intrinsic::cttz>(Op0) ||
      match(ThenV, m_Intrinsic<Intrinsic::ctlz>(Op0))

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:1631-1633
@@ +1630,5 @@
+        unsigned BitWidth = ThenV->getType()->getIntegerBitWidth();
+        ConstantInt *CInt = dyn_cast<ConstantInt>(OrigV);
+        if (!CInt || !CInt->equalsInt(BitWidth))
+          return false;
+
----------------
If you use `m_APInt`, this will also work with vector types.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:1635-1640
@@ +1634,8 @@
+
+        // Don't convert to select if 'ThenBB' is not on the false edge of the
+        // conditional branch.
+        if (!isa<ICmpInst>(BrCond))
+          return false;
+
+        ICmpInst *Cmp = cast<ICmpInst>(BrCond);
+        if (Cmp->getPredicate() != ICmpInst::ICMP_EQ ||
----------------
Please use dyn_cast.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:1643-1646
@@ +1642,6 @@
+            Cmp->getOperand(0) != II->getArgOperand(0) ||
+            !isa<ConstantInt>(Cmp->getOperand(1)) ||
+            // Make sure that 'ThenBB' is only taken if the input to the
+            // cttz/ctlz intrinsic call is not zero.
+            !cast<ConstantInt>(Cmp->getOperand(1))->isZero())
+          return false;
----------------
Why not just use `match(Cmp->getOperand(1), m_Zero())`

http://reviews.llvm.org/D6679

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list