Skip to content

Commit e2a855d

Browse files
committed
[InstCombine] Fix SimplifyDemandedBits recursion cutoff for Arguments
There was a discrepancy between how SimplifyDemandedBits and computeKnownBits handled the Argument case. computeKnownBits() would use information from range attributes even once the recursion limit has been reached. Fixes llvm#110631.
1 parent 091dc23 commit e2a855d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
104104
return true;
105105
}
106106

107-
if (Depth == MaxAnalysisRecursionDepth)
108-
return false;
109-
110107
Instruction *VInst = dyn_cast<Instruction>(V);
111108
if (!VInst) {
112109
llvm::computeKnownBits(V, Known, Depth, Q);
113110
return false;
114111
}
115112

113+
if (Depth == MaxAnalysisRecursionDepth)
114+
return false;
115+
116116
Value *NewVal;
117117
if (VInst->hasOneUse()) {
118118
// If the instruction has one use, we can directly simplify it.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=instcombine -instcombine-verify-known-bits < %s | FileCheck %s
3+
4+
define i16 @pr110631(i32 range(i32 0, 256) %arg, i64 %arg1) {
5+
; CHECK-LABEL: define i16 @pr110631(
6+
; CHECK-SAME: i32 range(i32 0, 256) [[ARG:%.*]], i64 [[ARG1:%.*]]) {
7+
; CHECK-NEXT: [[BB:.*:]]
8+
; CHECK-NEXT: [[I:%.*]] = xor i32 [[ARG]], 48991
9+
; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[ARG1]] to i32
10+
; CHECK-NEXT: [[I4:%.*]] = and i32 [[I]], [[TMP0]]
11+
; CHECK-NEXT: [[TMP1:%.*]] = trunc nuw i32 [[I4]] to i16
12+
; CHECK-NEXT: [[I8:%.*]] = xor i16 [[TMP1]], 1
13+
; CHECK-NEXT: ret i16 [[I8]]
14+
;
15+
bb:
16+
%i = xor i32 %arg, 48991
17+
%i2 = zext i32 %i to i64
18+
%i3 = and i64 %arg1, %i2
19+
%i4 = trunc i64 %i3 to i32
20+
%i5 = trunc i32 %i4 to i16
21+
%i6 = sext i16 %i5 to i32
22+
%i7 = xor i32 %i6, 1
23+
%i8 = trunc i32 %i7 to i16
24+
ret i16 %i8
25+
}

0 commit comments

Comments
 (0)