Index: lib/Analysis/ScopDetection.cpp =================================================================== --- lib/Analysis/ScopDetection.cpp +++ lib/Analysis/ScopDetection.cpp @@ -524,7 +524,7 @@ const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) { return Expr; } const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) { - if (Expr->getOperand(0)->isZero()) { + if ((Expr->getNumOperands() == 2) and Expr->getOperand(0)->isZero()) { auto Res = visit(Expr->getOperand(1)); if (Terms) (*Terms).push_back(Res); @@ -534,7 +534,7 @@ return Expr; } - const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) { return visit(Expr); } + const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) { return Expr; } const SCEV *visitUnknown(const SCEVUnknown *Expr) { return Expr; } Index: test/ScopDetect/scev_remove_max.ll =================================================================== --- /dev/null +++ test/ScopDetect/scev_remove_max.ll @@ -0,0 +1,33 @@ +; RUN: opt %loadPolly -polly-detect < %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@vertPlane = external global i8*, align 8 + +define fastcc void @Maze2Mech(i64 %i, i64 %b1, i64 %yStart) { +.split: + br i1 undef, label %DrawSegment.exit, label %DrawSegment.exit34 + +DrawSegment.exit34: ; preds = %.split + %0 = icmp ugt i64 %yStart, %b1 + %1 = select i1 %0, i64 %b1, i64 %yStart + %2 = load i8*, i8** @vertPlane, align 8 + %y.04.i21 = add i64 %1, 1 + br label %.lr.ph.i24 + +.lr.ph.i24: ; preds = %.lr.ph.i24, %DrawSegment.exit34 + %y.05.i22 = phi i64 [ %y.0.i23, %.lr.ph.i24 ], [ %y.04.i21, %DrawSegment.exit34 ] + %3 = mul i64 %y.05.i22, undef + %4 = add i64 %3, %i + %5 = getelementptr inbounds i8, i8* %2, i64 %4 + store i8 undef, i8* %5, align 1 + %y.0.i23 = add nuw i64 %y.05.i22, 1 + br i1 false, label %6, label %.lr.ph.i24 + +;