[PATCH] D18305: [InstCombine] Ensure all undef operands are handled before binary instruction constant folding

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 11:58:58 PDT 2016


RKSimon updated this revision to Diff 51205.
RKSimon added a comment.

Moved isBinaryOp assert to start of function - with that done we can remove the 'default' option for undef handling and just assert afterward that neither operand is undef, this will pick up any current/future binary instructions that we don't handle undefs for.


Repository:
  rL LLVM

http://reviews.llvm.org/D18305

Files:
  lib/IR/ConstantFold.cpp

Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp
+++ lib/IR/ConstantFold.cpp
@@ -916,6 +916,8 @@
 
 Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
                                               Constant *C1, Constant *C2) {
+  assert(Instruction::isBinaryOp(Opcode) && "Non-binary instruction detected");
+
   // Handle UndefValue up front.
   if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
     switch (Opcode) {
@@ -998,9 +1000,20 @@
         return C1;
       // undef << X -> 0
       return Constant::getNullValue(C1->getType());
+    case Instruction::FAdd:
+    case Instruction::FSub:
+    case Instruction::FMul:
+    case Instruction::FDiv:
+    case Instruction::FRem:
+      // TODO: UNDEF handling for binary float instructions.
+      return nullptr;
     }
   }
 
+  // At this point neither constant should be an UndefValue.
+  assert(!isa<UndefValue>(C1) && !isa<UndefValue>(C2) &&
+         "Unexpected UndefValue");
+
   // Handle simplifications when the RHS is a constant int.
   if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
     switch (Opcode) {
@@ -1102,7 +1115,6 @@
       return ConstantExpr::get(Opcode, C2, C1);
   }
 
-  // At this point we know neither constant is an UndefValue.
   if (ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
     if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
       const APInt &C1V = CI1->getValue();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18305.51205.patch
Type: text/x-patch
Size: 1469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160321/44f43658/attachment.bin>


More information about the llvm-commits mailing list