Skip to content

Commit

Permalink
[JumpThreading] add a miscompile test based on discussion in D76332; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Mar 18, 2020
1 parent 498b538 commit 22c66c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions llvm/test/Transforms/JumpThreading/select.ll
Expand Up @@ -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
}

0 comments on commit 22c66c1

Please sign in to comment.