From 2659e1bf4b54cf9c2fadac0813e5e0ab4d2c49d5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 15 Jul 2022 17:06:07 +0200 Subject: [PATCH] [SCEV] List all binops in getOperandsToCreate() Explicitly list all binops rather than having a default case. There were two bugs here: 1. U->getOpcode() was used instead of BO->Opcode, which means we used the logic for the wrong opcode in some cases. 2. SCEV construction does not support LShr. We should return unknown for it rather than recursing into the operands. --- llvm/lib/Analysis/ScalarEvolution.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7fd2553..c0924fc 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -7249,7 +7249,7 @@ ScalarEvolution::getOperandsToCreate(Value *V, SmallVectorImpl &Ops) { Operator *U = cast(V); if (auto BO = MatchBinaryOp(U, DT)) { bool IsConstArg = isa(BO->RHS); - switch (U->getOpcode()) { + switch (BO->Opcode) { case Instruction::Add: { // For additions and multiplications, traverse add/mul chains for which we // can potentially create a single SCEV, to reduce the number of @@ -7291,7 +7291,10 @@ ScalarEvolution::getOperandsToCreate(Value *V, SmallVectorImpl &Ops) { } while (true); return nullptr; } - + case Instruction::Sub: + case Instruction::UDiv: + case Instruction::URem: + break; case Instruction::AShr: case Instruction::Shl: case Instruction::Xor: @@ -7303,7 +7306,10 @@ ScalarEvolution::getOperandsToCreate(Value *V, SmallVectorImpl &Ops) { if (!IsConstArg && BO->LHS->getType()->isIntegerTy(1)) return nullptr; break; + case Instruction::LShr: + return getUnknown(V); default: + llvm_unreachable("Unhandled binop"); break; } -- 2.7.4