[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
Sun Mar 20 13:28:38 PDT 2016


RKSimon created this revision.
RKSimon added reviewers: majnemer, bogner.
RKSimon added a subscriber: llvm-commits.
RKSimon set the repository for this revision to rL LLVM.

As noted in PR18355, this patch makes it clear that all cases with undef operands have been handled before further constant folding is attempted.

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
@@ -998,9 +998,16 @@
         return C1;
       // undef << X -> 0
       return Constant::getNullValue(C1->getType());
+    default:
+      // We don't know how to handle UNDEFs in this instruction.
+      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 +1109,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.51133.patch
Type: text/x-patch
Size: 1008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160320/70e75822/attachment.bin>


More information about the llvm-commits mailing list