Skip to content

Commit 22c66c1

Browse files
committed
[JumpThreading] add a miscompile test based on discussion in D76332; NFC
1 parent 498b538 commit 22c66c1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

llvm/test/Transforms/JumpThreading/select.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,31 @@ sw.default: ; preds = %if.end, %sw.bb9
441441
; CHECK: i32 2, label [[DEST1]]
442442
; CHECK: i32 4, label [[DEST2]]
443443
}
444+
445+
; FIXME: This is an invalid transform. If %b is false and %x is poison,
446+
; then the select produces poison (the result of the program is poison).
447+
; But with this transform, we may be branching on poison, and that is UB.
448+
449+
define i32 @TryToUnfoldSelectInCurrBB(i1 %b, i1 %ui, i32 %s, i1 %x) {
450+
; CHECK-LABEL: @TryToUnfoldSelectInCurrBB(
451+
; CHECK-NEXT: entry:
452+
; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_END_THREAD:%.*]], label [[IF_END:%.*]]
453+
; CHECK: if.end:
454+
; CHECK-NEXT: br i1 [[X:%.*]], label [[TMP0:%.*]], label [[IF_END_THREAD]]
455+
; CHECK: 0:
456+
; CHECK-NEXT: br label [[IF_END_THREAD]]
457+
; CHECK: if.end.thread:
458+
; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[S:%.*]], [[TMP0]] ], [ 42, [[IF_END]] ], [ 42, [[ENTRY:%.*]] ]
459+
; CHECK-NEXT: ret i32 [[TMP1]]
460+
;
461+
entry:
462+
br i1 %b, label %if.end, label %if.else
463+
464+
if.else:
465+
br label %if.end
466+
467+
if.end:
468+
%v = phi i1 [ %x, %if.else ], [ false, %entry ]
469+
%v1 = select i1 %v, i32 %s, i32 42
470+
ret i32 %v1
471+
}

0 commit comments

Comments
 (0)