[InstCombine] Don't assume m_Mul gives back an Instruction
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 5 Sep 2015 20:44:56 +0000 (20:44 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 5 Sep 2015 20:44:56 +0000 (20:44 +0000)
This fixes PR24713.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246933 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll

index 6e4336ef87543fb88d53f49ae3342748d30e73cd..b3366bb988896aceead3ca73ab526b9564cee828 100644 (file)
@@ -2246,7 +2246,9 @@ static Instruction *ProcessUMulZExtIdiom(ICmpInst &I, Value *MulVal,
 
   assert(I.getOperand(0) == MulVal || I.getOperand(1) == MulVal);
   assert(I.getOperand(0) == OtherVal || I.getOperand(1) == OtherVal);
-  Instruction *MulInstr = cast<Instruction>(MulVal);
+  auto *MulInstr = dyn_cast<Instruction>(MulVal);
+  if (!MulInstr)
+    return nullptr;
   assert(MulInstr->getOpcode() == Instruction::Mul);
 
   auto *LHS = cast<ZExtOperator>(MulInstr->getOperand(0)),
index 5d97411625ebf6a8d587ac5e58d9780ef53fa01a..e351c81b15a5b01e151b67e6164707dda65c62f6 100644 (file)
@@ -1623,3 +1623,12 @@ define i1 @f9(i32 %val, i32 %lim) {
   %r = icmp ult i32 %val.and, %lim
   ret i1 %r
 }
+
+; CHECK: @f10(
+; CHECK: [[CMP:%.*]] = icmp uge i16 %p, mul (i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16), i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16))
+; CHECK-NEXT: ret i1 [[CMP]]
+define i1 @f10(i16 %p) {
+entry:
+  %cmp580 = icmp ule i16 mul (i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16), i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16)), %p
+  ret i1 %cmp580
+}