<div class="gmail_quote">2009/11/9 Chris Lattner <span dir="ltr"><<a href="mailto:sabre@nondot.org">sabre@nondot.org</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Author: lattner<br>
Date: Mon Nov  9 16:57:59 2009<br>
New Revision: 86613<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=86613&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=86613&view=rev</a><br>
Log:<br>
stub out a new libanalysis "instruction simplify" interface that<br>
takes decimated instructions and applies identities to them.  This<br>
is pretty minimal at this point, but I plan to pull some instcombine<br>
logic out into these and similar routines.<br>
<br>
Added:<br>
    llvm/trunk/include/llvm/Analysis/InstructionSimplify.h<br>
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
Modified:<br>
    llvm/trunk/lib/Analysis/CMakeLists.txt<br>
<br>
Added: llvm/trunk/include/llvm/Analysis/InstructionSimplify.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InstructionSimplify.h?rev=86613&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InstructionSimplify.h?rev=86613&view=auto</a><br>


<br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/InstructionSimplify.h (added)<br>
+++ llvm/trunk/include/llvm/Analysis/InstructionSimplify.h Mon Nov  9 16:57:59 2009<br>
@@ -0,0 +1,37 @@<br>
+//===-- InstructionSimplify.h - Fold instructions into simpler forms ------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file declares routines for folding instructions into simpler forms that<br>
+// do not require creating new instructions.  For example, this does constant<br>
+// folding, and can handle identities like (X&0)->0.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H<br>
+#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H<br>
+<br>
+namespace llvm {<br>
+  class Value;<br>
+  class TargetData;<br>
+<br>
+  /// SimplifyCompare - Given operands for a CmpInst, see if we can<br>
+  /// fold the result.  If not, this returns null.<br>
+  Value *SimplifyCompare(unsigned Predicate, Value *LHS, Value *RHS,<br>
+                         const TargetData *TD = 0);<br>
+<br>
+<br>
+  /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can<br>
+  /// fold the result.  If not, this returns null.<br>
+  Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,<br>
+                       const TargetData *TD = 0);<br>
+<br>
+} // end namespace llvm<br>
+<br>
+#endif<br>
+<br>
<br>
Modified: llvm/trunk/lib/Analysis/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CMakeLists.txt?rev=86613&r1=86612&r2=86613&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CMakeLists.txt?rev=86613&r1=86612&r2=86613&view=diff</a><br>


<br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/Analysis/CMakeLists.txt Mon Nov  9 16:57:59 2009<br>
@@ -15,6 +15,7 @@<br>
   IVUsers.cpp<br>
   InlineCost.cpp<br>
   InstCount.cpp<br>
+  InstructionSimplify.cpp<br>
   Interval.cpp<br>
   IntervalPartition.cpp<br>
   LibCallAliasAnalysis.cpp<br>
<br>
Added: llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=86613&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=86613&view=auto</a><br>


<br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (added)<br>
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Nov  9 16:57:59 2009<br>
@@ -0,0 +1,57 @@<br>
+//===- InstructionSimplify.cpp - Fold instruction operands ----------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file implements routines for folding instructions into simpler forms<br>
+// that do not require creating new instructions.  For example, this does<br>
+// constant folding, and can handle identities like (X&0)->0.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/Analysis/InstructionSimplify.h"<br>
+#include "llvm/Analysis/ConstantFolding.h"<br>
+#include "llvm/Instructions.h"<br>
+using namespace llvm;<br>
+<br>
+<br>
+/// SimplifyBinOp - Given operands for a BinaryOperator, see if we can<br>
+/// fold the result.  If not, this returns null.<br>
+Value *llvm::SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,<br>
+                           const TargetData *TD) {<br>
+  if (Constant *CLHS = dyn_cast<Constant>(LHS))<br>
+    if (Constant *CRHS = dyn_cast<Constant>(RHS)) {<br>
+      Constant *COps[] = {CLHS, CRHS};<br>
+      return ConstantFoldInstOperands(Opcode, LHS->getType(), COps, 2, TD);<br>
+    }<br>
+  return 0;<br>
+}<br>
+<br>
+<br>
+/// SimplifyCompare - Given operands for a CmpInst, see if we can<br>
+/// fold the result.<br>
+Value *llvm::SimplifyCompare(unsigned Predicate, Value *LHS, Value *RHS,<br>
+                             const TargetData *TD) {<br>
+  CmpInst::Predicate Pred = (CmpInst::Predicate)Predicate;<br>
+<br>
+  if (Constant *CLHS = dyn_cast<Constant>(LHS))<br>
+    if (Constant *CRHS = dyn_cast<Constant>(RHS)) {<br>
+      Constant *COps[] = {CLHS, CRHS};<br>
+      return ConstantFoldCompareInstOperands(Pred, COps, 2, TD);<br>
+    }<br>
+<br>
+  // If this is an integer compare and the LHS and RHS are the same, fold it.<br>
+  if (LHS == RHS)<br>
+    if (isa<IntegerType>(LHS->getType()) || isa<PointerType>(LHS->getType())) {<br>
+      if (ICmpInst::isTrueWhenEqual(Pred))<br>
+        return ConstantInt::getTrue(LHS->getContext());<br>
+      else<br>
+        return ConstantInt::getFalse(LHS->getContext());<br>
+    }<br>
</blockquote><div><br>There's an CmpInst::isTrueWhenEqual and CmpInst::isFalseWhenEqual, both of which work on icmp and fcmp. Please use that instead, adding support for floats in the process!<br><br>Nick<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

+  return 0;<br>
+}<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>