Index: lib/Transforms/Scalar/LoopUnrollPass.cpp =================================================================== --- lib/Transforms/Scalar/LoopUnrollPass.cpp +++ lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -424,6 +424,29 @@ return true; } + bool visitCastInst(CastInst &I) { + if (SCEVSimplify(&I)) + return true; + // If we've already visited the operand and found a base pointer for it, we + // can't const-fold it other than when used in a load. + if (auto *Op0 = dyn_cast(I.getOperand(0))) + if (GEPPointerBases.lookup(Op0)) + return false; + + // Propagate constants through ptrtoint. + Constant *COp = dyn_cast(I.getOperand(0)); + if (!COp) + COp = SimplifiedValues.lookup(I.getOperand(0)); + if (COp) + if (Constant *C = + ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { + SimplifiedValues[&I] = C; + return true; + } + + return false; + } + bool visitCmpInst(CmpInst &I) { if (SCEVSimplify(&I)) return true;