+ // If we're in an invariant region, no dependencies can be found before
+ // we pass an invariant-begin marker.
+ if (invariantTag == Inst) {
+ invariantTag = 0;
+ continue;
+
+ // If we pass an invariant-end marker, then we've just entered an invariant
+ // region and can start ignoring dependencies.
+ } else if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(Inst)) {
+ if (II->getIntrinsicID() == Intrinsic::invariant_end) {
+ uint64_t invariantSize = ~0ULL;
+ if (ConstantInt* CI = dyn_cast<ConstantInt>(II->getOperand(2)))
+ invariantSize = CI->getZExtValue();
+
+ AliasAnalysis::AliasResult R =
+ AA->alias(II->getOperand(3), invariantSize, MemPtr, MemSize);
+ if (R == AliasAnalysis::MustAlias) {
+ invariantTag = II->getOperand(1);
+ continue;
+ }
+ }
+ }
+
+ // If we're querying on a load and we're in an invariant region, we're done
+ // at this point. Nothing a load depends on can live in an invariant region.
+ if (isLoad && invariantTag) continue;
+