Skip to content

Commit 9636118

Browse files
committed
[ValueTracking] Bail out on non-immediate constant expressions
1 parent c42fcdd commit 9636118

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,8 @@ findValuesAffectedByCondition(Value *Cond, bool IsAssume,
10241024
LLVM_ABI Value *stripNullTest(Value *V);
10251025
LLVM_ABI const Value *stripNullTest(const Value *V);
10261026

1027-
/// Enumerates all possible values of V and inserts them into the set \p
1028-
/// Constants. If \p AllowUndefOrPoison is false, it fails when V may contain
1027+
/// Enumerates all possible immediate values of V and inserts them into the set
1028+
/// \p Constants. If \p AllowUndefOrPoison is false, it fails when V may contain
10291029
/// undef/poison elements. Returns true if the result is complete. Otherwise,
10301030
/// the result is incomplete (more than MaxCount values).
10311031
/// NOTE: The constant values are not distinct.

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10485,7 +10485,8 @@ bool llvm::collectPossibleValues(const Value *V,
1048510485
SmallPtrSet<const Instruction *, 8> Visited;
1048610486
SmallVector<const Instruction *, 8> Worklist;
1048710487
auto Push = [&](const Value *V) -> bool {
10488-
if (auto *C = dyn_cast<Constant>(V)) {
10488+
Constant *C;
10489+
if (match(const_cast<Value *>(V), m_ImmConstant(C))) {
1048910490
if (!AllowUndefOrPoison && !isGuaranteedNotToBeUndefOrPoison(C))
1049010491
return false;
1049110492
// Check existence first to avoid unnecessary allocations.

llvm/test/Transforms/SimplifyCFG/switch-on-const.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ default:
287287
define i16 @switch_on_nonimmediate_constant_expr() {
288288
; CHECK-LABEL: @switch_on_nonimmediate_constant_expr(
289289
; CHECK-NEXT: entry:
290-
; CHECK-NEXT: ret i16 789
290+
; CHECK-NEXT: [[SWITCH_SELECTCMP:%.*]] = icmp eq i32 ptrtoint (ptr @G to i32), 2
291+
; CHECK-NEXT: [[SWITCH_SELECT:%.*]] = select i1 [[SWITCH_SELECTCMP]], i16 456, i16 789
292+
; CHECK-NEXT: [[SWITCH_SELECTCMP1:%.*]] = icmp eq i32 ptrtoint (ptr @G to i32), 1
293+
; CHECK-NEXT: [[SWITCH_SELECT2:%.*]] = select i1 [[SWITCH_SELECTCMP1]], i16 123, i16 [[SWITCH_SELECT]]
294+
; CHECK-NEXT: ret i16 [[SWITCH_SELECT2]]
291295
;
292296
entry:
293297
switch i32 ptrtoint (ptr @G to i32), label %sw.default [

0 commit comments

Comments
 (0)