[JumpThreading] add a miscompile test based on discussion in D76332; NFC

This commit is contained in:
Sanjay Patel 2020-03-18 16:26:01 -04:00
parent 1581f309d4
commit 9b17097170

View File

@ -441,3 +441,31 @@ sw.default: ; preds = %if.end, %sw.bb9
; CHECK: i32 2, label [[DEST1]]
; CHECK: i32 4, label [[DEST2]]
}
; FIXME: This is an invalid transform. If %b is false and %x is poison,
; then the select produces poison (the result of the program is poison).
; But with this transform, we may be branching on poison, and that is UB.
define i32 @TryToUnfoldSelectInCurrBB(i1 %b, i1 %ui, i32 %s, i1 %x) {
; CHECK-LABEL: @TryToUnfoldSelectInCurrBB(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_END_THREAD:%.*]], label [[IF_END:%.*]]
; CHECK: if.end:
; CHECK-NEXT: br i1 [[X:%.*]], label [[TMP0:%.*]], label [[IF_END_THREAD]]
; CHECK: 0:
; CHECK-NEXT: br label [[IF_END_THREAD]]
; CHECK: if.end.thread:
; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[S:%.*]], [[TMP0]] ], [ 42, [[IF_END]] ], [ 42, [[ENTRY:%.*]] ]
; CHECK-NEXT: ret i32 [[TMP1]]
;
entry:
br i1 %b, label %if.end, label %if.else
if.else:
br label %if.end
if.end:
%v = phi i1 [ %x, %if.else ], [ false, %entry ]
%v1 = select i1 %v, i32 %s, i32 42
ret i32 %v1
}