[llvm-commits] [PATCH] Teach IRBuilder about simplifying BinOp(Value, Constant)

Török Edwin edwintorok at gmail.com
Sat Jan 3 08:52:06 PST 2009


On 2009-01-03 18:45, Nick Lewycky wrote:
> Hey Edwin,
>
> The one thing I encountered when playing around with IRBuilder isn't 
> handled here: select constant, value, value. This comes up due to 
> expressions like sizeof(ptr)==32 ? X : Y. The existing constant folder 
> need all three operands to be constant.
>
> Could you add that case?
>
>   

Hi Nick,

The patch already handles your case, I just forgot to mention that in
the "noteworthy changes":

   Value *CreateSelect(Value *C, Value *True, Value *False,
                       const char *Name = "") {
-    if (Constant *CC = dyn_cast<Constant>(C))
+    if (Constant *CC = dyn_cast<Constant>(C)) {
+      if (const ConstantInt *CB = dyn_cast<ConstantInt>(CC))
+        return CB->getZExtValue() ? True : False;
       if (Constant *TC = dyn_cast<Constant>(True))
         if (Constant *FC = dyn_cast<Constant>(False))
           return Folder.CreateSelect(CC, TC, FC);
+    }
     return Insert(SelectInst::Create(C, True, False), Name);
   }

If there are no objections to the patch, can I commit it?
Or should I wait till llvm-gcc bootstrap is unbroken?

Best regards,
--Edwin



More information about the llvm-commits mailing list