From 4402d0d4fbdb903bd61238a06cfad29b4dd2da0b Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 19 Jul 2021 15:11:38 -0700 Subject: [PATCH] [SCEV] Add a clarifying comment in howManyLessThans Wrap semantics are subtle when combined with multiple exits. This has caused several rounds of confusion during recent reviews, so try to document the subtly distinction between when wrap flags provide getLoop() != L || !IV->isAffine()) return getCouldNotCompute(); + // A precondition of this method is that the condition being analyzed + // reaches an exiting branch which dominates the latch. Given that, we can + // assume that an increment which violates the nowrap specification and + // produces poison must cause undefined behavior when the resulting poison + // value is branched upon and thus we can conclude that the backedge is + // taken no more often than would be required to produce that poison value. + // Note that a well defined loop can exit on the iteration which violates + // the nowrap specification if there is another exit (either explicit or + // implicit/exceptional) which causes the loop to execute before the + // exiting instruction we're analyzing would trigger UB. auto WrapType = IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW; bool NoWrap = ControlsExit && IV->getNoWrapFlags(WrapType); ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; -- 2.7.4