From 6456d06226cac950e12df13bb8bfa14be8ca4a1b Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 5 Sep 2015 20:44:56 +0000 Subject: [PATCH] [InstCombine] Don't assume m_Mul gives back an Instruction 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 | 4 +++- test/Transforms/InstCombine/icmp.ll | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 6e4336ef875..b3366bb9888 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -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(MulVal); + auto *MulInstr = dyn_cast(MulVal); + if (!MulInstr) + return nullptr; assert(MulInstr->getOpcode() == Instruction::Mul); auto *LHS = cast(MulInstr->getOperand(0)), diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index 5d97411625e..e351c81b15a 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -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 +} -- 2.34.1