[llvm] 2659e1b - [SCEV] List all binops in getOperandsToCreate()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 15 08:08:56 PDT 2022


Author: Nikita Popov
Date: 2022-07-15T17:08:48+02:00
New Revision: 2659e1bf4b54cf9c2fadac0813e5e0ab4d2c49d5

URL: https://github.com/llvm/llvm-project/commit/2659e1bf4b54cf9c2fadac0813e5e0ab4d2c49d5
DIFF: https://github.com/llvm/llvm-project/commit/2659e1bf4b54cf9c2fadac0813e5e0ab4d2c49d5.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7fd2553b07964..c0924fcf8438f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7249,7 +7249,7 @@ ScalarEvolution::getOperandsToCreate(Value *V, SmallVectorImpl<Value *> &Ops) {
   Operator *U = cast<Operator>(V);
   if (auto BO = MatchBinaryOp(U, DT)) {
     bool IsConstArg = isa<ConstantInt>(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<Value *> &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<Value *> &Ops) {
       if (!IsConstArg && BO->LHS->getType()->isIntegerTy(1))
         return nullptr;
       break;
+    case Instruction::LShr:
+      return getUnknown(V);
     default:
+      llvm_unreachable("Unhandled binop");
       break;
     }
 


        


More information about the llvm-commits mailing list