Implement constant propogation of shifts
authorChris Lattner <sabre@nondot.org>
Mon, 6 May 2002 03:00:54 +0000 (03:00 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 6 May 2002 03:00:54 +0000 (03:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2470 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 5fd11c3a2ecc33be34c0dae69646e41f57aef9d5..ee7d43e919004a9b81cb1f1cca6c2450d1f1a52f 100644 (file)
@@ -56,6 +56,14 @@ class TemplateRules : public ConstRules {
                         const Constant *V2) const { 
     return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);  
   }
+  virtual Constant *shl(const Constant *V1, 
+                        const Constant *V2) const { 
+    return SubClassName::Shl((const ArgType *)V1, (const ArgType *)V2);  
+  }
+  virtual Constant *shr(const Constant *V1, 
+                        const Constant *V2) const { 
+    return SubClassName::Shr((const ArgType *)V1, (const ArgType *)V2);  
+  }
 
   virtual ConstantBool *lessthan(const Constant *V1, 
                                  const Constant *V2) const { 
@@ -122,6 +130,12 @@ class TemplateRules : public ConstRules {
   inline static Constant *Rem(const ArgType *V1, const ArgType *V2) {
     return 0;
   }
+  inline static Constant *Shl(const ArgType *V1, const ArgType *V2) {
+    return 0;
+  }
+  inline static Constant *Shr(const ArgType *V1, const ArgType *V2) {
+    return 0;
+  }
   inline static ConstantBool *LessThan(const ArgType *V1, const ArgType *V2) {
     return 0;
   }
@@ -337,6 +351,20 @@ struct DirectIntRules
                          (BuiltinType)V2->getValue();
     return ConstantClass::get(*Ty, Result);
   }
+
+  inline static Constant *Shl(const ConstantClass *V1,
+                              const ConstantClass *V2) {
+    BuiltinType Result = (BuiltinType)V1->getValue() <<
+                         (BuiltinType)V2->getValue();
+    return ConstantClass::get(*Ty, Result);
+  }
+
+  inline static Constant *Shr(const ConstantClass *V1,
+                              const ConstantClass *V2) {
+    BuiltinType Result = (BuiltinType)V1->getValue() >>
+                         (BuiltinType)V2->getValue();
+    return ConstantClass::get(*Ty, Result);
+  }
 };