Skip to content

Commit ace0bf7

Browse files
committed
[ValueTracking] Fix incorrect handling of canCreateUndefOrPoison
.. in isGuaranteedNotToBeUndefOrPoison. This caused early exit of isGuaranteedNotToBeUndefOrPoison, making it return imprecise result. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D84251
1 parent 18581fd commit ace0bf7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4824,10 +4824,7 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V,
48244824
return true;
48254825
}
48264826

4827-
if (canCreateUndefOrPoison(Opr))
4828-
return false;
4829-
4830-
if (all_of(Opr->operands(), OpCheck))
4827+
if (!canCreateUndefOrPoison(Opr) && all_of(Opr->operands(), OpCheck))
48314828
return true;
48324829
}
48334830

llvm/test/Transforms/InstSimplify/freeze.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ EXIT:
381381
ret i32 %fr2
382382
}
383383

384+
declare i32 @any_num()
385+
386+
define i32 @brcond_call() {
387+
; CHECK-LABEL: @brcond_call(
388+
; CHECK-NEXT: [[X:%.*]] = call i32 @any_num()
389+
; CHECK-NEXT: switch i32 [[X]], label [[EXIT:%.*]] [
390+
; CHECK-NEXT: ]
391+
; CHECK: EXIT:
392+
; CHECK-NEXT: ret i32 [[X]]
393+
;
394+
%x = call i32 @any_num()
395+
switch i32 %x, label %EXIT []
396+
EXIT:
397+
%y = freeze i32 %x
398+
ret i32 %y
399+
}
400+
384401
define i1 @brcond_noopt(i1 %c, i1 %c2) {
385402
; CHECK-LABEL: @brcond_noopt(
386403
; CHECK-NEXT: [[F:%.*]] = freeze i1 [[C:%.*]]

0 commit comments

Comments
 (0)