From ed297abb0a9317e7b58d66bc8671d6306d6e1fff Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 1 Nov 2014 23:46:05 +0000 Subject: [PATCH] InstCombine: Don't assume that m_ZExt matches an Instruction m_ZExt might bind against a ConstantExpr instead of an Instruction. Assuming this, using cast, results in InstCombine crashing. Instead, introduce ZExtOperator to bridge both Instruction and ConstantExpr ZExts. This fixes PR21445. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221069 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Operator.h | 2 ++ lib/Transforms/InstCombine/InstCombineCompares.cpp | 4 ++-- test/Transforms/InstCombine/overflow-mul.ll | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/llvm/IR/Operator.h b/include/llvm/IR/Operator.h index dba44b94f15..0933f217023 100644 --- a/include/llvm/IR/Operator.h +++ b/include/llvm/IR/Operator.h @@ -358,6 +358,8 @@ class LShrOperator }; +class ZExtOperator : public ConcreteOperator {}; + class GEPOperator : public ConcreteOperator { diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index bd1b67ddcfa..f7eb16cbb96 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2160,8 +2160,8 @@ static Instruction *ProcessUMulZExtIdiom(ICmpInst &I, Value *MulVal, Instruction *MulInstr = cast(MulVal); assert(MulInstr->getOpcode() == Instruction::Mul); - Instruction *LHS = cast(MulInstr->getOperand(0)), - *RHS = cast(MulInstr->getOperand(1)); + auto *LHS = cast(MulInstr->getOperand(0)), + *RHS = cast(MulInstr->getOperand(1)); assert(LHS->getOpcode() == Instruction::ZExt); assert(RHS->getOpcode() == Instruction::ZExt); Value *A = LHS->getOperand(0), *B = RHS->getOperand(0); diff --git a/test/Transforms/InstCombine/overflow-mul.ll b/test/Transforms/InstCombine/overflow-mul.ll index cbb2f5f9500..6d8d40bcac3 100644 --- a/test/Transforms/InstCombine/overflow-mul.ll +++ b/test/Transforms/InstCombine/overflow-mul.ll @@ -173,3 +173,16 @@ define <4 x i32> @pr20113(<4 x i16> %a, <4 x i16> %b) { %vcgez.i = sext <4 x i1> %tmp to <4 x i32> ret <4 x i32> %vcgez.i } + +@pr21445_data = external global i32 +define i1 @pr21445(i8 %a) { +; CHECK-LABEL: @pr21445( +; CHECK-NEXT: %[[umul:.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 ptrtoint (i32* @pr21445_data to i8)) +; CHECK-NEXT: %[[cmp:.*]] = extractvalue { i8, i1 } %[[umul]], 1 +; CHECK-NEXT: ret i1 %[[cmp]] + %ext = zext i8 %a to i32 + %mul = mul i32 %ext, zext (i8 ptrtoint (i32* @pr21445_data to i8) to i32) + %and = and i32 %mul, 255 + %cmp = icmp ne i32 %mul, %and + ret i1 %cmp +} -- 2.34.1