This fixes a violation of the wrap flag rules introduced in c4048d8f. This was also noted in the (very old) PR23527.
The issue being fixed is that we assume the inbound flag on any GEP assumes that all users of *any* gep (or add) which happens to map to that SCEV would also be UB if the (other) gep overflowed. That's simply not true.
In terms of the test diffs, I don't see anything seriously problematic. The lost flags are expected (given the semantic restriction on when its legal to tag the SCEV), and there are several cases where the previously inferred flags are unsound per the new semantics.
The only common trend I noticed when looking at the deltas is that by not considering branch on poison as immediate UB in ValueTracking, we do miss a few cases we could reclaim. We may be able to claw some of these back with the follow ideas mentioned in PR51817.
It's worth noting that most of the changes are analysis result only changes. The two transform changes are pretty minimal. In one case, we miss the opportunity to infer a nuw (correctly). In the other, we fail to fold an exit and produce a loop invariant form instead. This one is probably over-reduced as the program appears to be undefined in practice, and neither before or after exploits that.
Differential Revision: https://reviews.llvm.org/D109789
45 lines
1.8 KiB
LLVM
45 lines
1.8 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -indvars -S < %s | FileCheck %s
|
|
|
|
; Check the case where one exit has a pointer EC, and the other doesn't.
|
|
; Note that this test case is really really fragile. Removing any
|
|
; instruction in the below causes the result to differ. Note that the lack
|
|
; of a data layout (with pointer size info) is critical to getting a pointer
|
|
; EC returned by SCEV.
|
|
|
|
@global = external global [0 x i8], align 1
|
|
|
|
define void @foo() {
|
|
; CHECK-LABEL: @foo(
|
|
; CHECK-NEXT: bb:
|
|
; CHECK-NEXT: br label [[BB3:%.*]]
|
|
; CHECK: bb3:
|
|
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i8, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @global, i64 0, i64 2), i64 -1
|
|
; CHECK-NEXT: [[TMP6:%.*]] = load i8, i8* [[TMP4]], align 1
|
|
; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i8* [[TMP4]], getelementptr inbounds ([0 x i8], [0 x i8]* @global, i64 0, i64 500)
|
|
; CHECK-NEXT: br i1 [[TMP5]], label [[BB7:%.*]], label [[BB11:%.*]]
|
|
; CHECK: bb7:
|
|
; CHECK-NEXT: [[TMP8:%.*]] = zext i8 [[TMP6]] to i64
|
|
; CHECK-NEXT: br i1 true, label [[BB11]], label [[BB3]]
|
|
; CHECK: bb11:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
bb:
|
|
br label %bb3
|
|
|
|
bb3: ; preds = %bb7, %bb2
|
|
%tmp = phi i8* [ %tmp4, %bb7 ], [ getelementptr inbounds ([0 x i8], [0 x i8]* @global, i64 0, i64 2), %bb ]
|
|
%tmp4 = getelementptr inbounds i8, i8* %tmp, i64 -1
|
|
%tmp6 = load i8, i8* %tmp4, align 1
|
|
%tmp5 = icmp ugt i8* %tmp4, getelementptr inbounds ([0 x i8], [0 x i8]* @global, i64 0, i64 500)
|
|
br i1 %tmp5, label %bb7, label %bb11
|
|
|
|
bb7: ; preds = %bb3
|
|
%tmp8 = zext i8 %tmp6 to i64
|
|
%tmp10 = icmp eq i16 0, 0
|
|
br i1 %tmp10, label %bb11, label %bb3
|
|
|
|
bb11: ; preds = %bb7, %bb3
|
|
ret void
|
|
}
|