// InstSimplify already performed this fold if it was possible subject to
// current poison-generating flags. Try the transform again with
// poison-generating flags temporarily dropped.
- bool WasNUW = false, WasNSW = false, WasExact = false;
+ bool WasNUW = false, WasNSW = false, WasExact = false, WasInBounds = false;
if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(FalseVal)) {
WasNUW = OBO->hasNoUnsignedWrap();
WasNSW = OBO->hasNoSignedWrap();
WasExact = PEO->isExact();
FalseInst->setIsExact(false);
}
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(FalseVal)) {
+ WasInBounds = GEP->isInBounds();
+ GEP->setIsInBounds(false);
+ }
// Try each equivalence substitution possibility.
// We have an 'EQ' comparison, so the select's false value will propagate.
FalseInst->setHasNoSignedWrap();
if (WasExact)
FalseInst->setIsExact();
+ if (WasInBounds)
+ cast<GetElementPtrInst>(FalseInst)->setIsInBounds();
return nullptr;
}
ret i32 %sel
}
+; TODO: Dropping the inbounds flag should not be necessary for this fold.
define i8* @select_replacement_gep_inbounds(i8* %base, i64 %offset) {
; CHECK-LABEL: @select_replacement_gep_inbounds(
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[OFFSET:%.*]], 0
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[BASE:%.*]], i64 [[OFFSET]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8* [[BASE]], i8* [[GEP]]
-; CHECK-NEXT: ret i8* [[SEL]]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[BASE:%.*]], i64 [[OFFSET:%.*]]
+; CHECK-NEXT: ret i8* [[GEP]]
;
%cmp = icmp eq i64 %offset, 0
%gep = getelementptr inbounds i8, i8* %base, i64 %offset