[Bug 14664] InstCombine missing canonicalization of sub-and into a select.

Nadav Rotem nrotem at apple.com
Tue Jan 29 09:46:09 PST 2013


Hi Muhammad, 

Please send patches to llvm-commit. 

+  {
+    Value *X = 0;
+    bool OpsSwapped = false;
+    // Canonicalize SExt or Not to the LHS
+    if (match(Op1, m_SExt(m_Value())) ||
+        match(Op1, m_Not(m_Value()))) {
+      std::swap(Op0, Op1);
+      OpsSwapped = true;
+    }
+
+    // Fold (and (sext bool to A), B) --> (select bool, B, 0)
+    if (match(Op0, m_SExt(m_Value(X))) &&
+        X->getType()->isIntegerTy(1)) {

Please make sure that this transformation also works with vector select.
+      Value *zero = Constant::getNullValue(Op1->getType());
zero -> Zero.
+      return SelectInst::Create(X, Op1, zero);
+    }
+
+    // Fold (and ~(sext bool to A), B) --> (select bool, 0, B)
+    if (match(Op0, m_Not(m_SExt(m_Value(X)))) &&
+        X->getType()->isIntegerTy(1)) {
+      Value *zero = Constant::getNullValue(Op0->getType());
+      return SelectInst::Create(X, zero, Op1);
Same as above.

+    }
+
+    if (OpsSwapped)
+      std::swap(Op0, Op1);
+  }
+
Thanks,
Nadav


On Jan 29, 2013, at 8:16 AM, bugzilla-daemon at llvm.org wrote:

> http://llvm.org/bugs/show_bug.cgi?id=14664
> 
> --- Comment #2 from Muhammad Tauqir <muhammad.t.ahmad at intel.com> 2013-01-29 10:16:39 CST ---
> Submitted a patch for the "second part" of the transform:
> sext-and --> select AND sext-not-and --> select.
> 
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130121/163154.html
> 
> Could someone please have a look?
> 
> -- 
> Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130129/844d271c/attachment.html>


More information about the llvm-commits mailing list