Skip to content

Commit 10869ad

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3613)
2 parents 0e388a0 + d8bfc31 commit 10869ad

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

libc/include/sys/ioctl.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ macros: []
55
types: []
66
enums: []
77
objects: []
8-
functions: []
8+
functions:
9+
- name: ioctl
10+
standards:
11+
- Linux
12+
return_type: int
13+
arguments:
14+
- type: int
15+
- type: unsigned long
16+
- type: '...'

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,13 @@ LazyValueInfoImpl::solveBlockValueCast(CastInst *CI, BasicBlock *BB) {
927927
// NOTE: We're currently limited by the set of operations that ConstantRange
928928
// can evaluate symbolically. Enhancing that set will allows us to analyze
929929
// more definitions.
930-
return ValueLatticeElement::getRange(LHSRange.castOp(CI->getOpcode(),
931-
ResultBitWidth));
930+
ConstantRange Res = ConstantRange::getEmpty(ResultBitWidth);
931+
if (auto *Trunc = dyn_cast<TruncInst>(CI))
932+
Res = LHSRange.truncate(ResultBitWidth, Trunc->getNoWrapKind());
933+
else
934+
Res = LHSRange.castOp(CI->getOpcode(), ResultBitWidth);
935+
936+
return ValueLatticeElement::getRange(Res);
932937
}
933938

934939
std::optional<ValueLatticeElement>

llvm/test/Transforms/CorrelatedValuePropagation/trunc.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,43 @@ define i1 @overdefined_range_negative(i8 %A, i8 %B) {
106106
%trunc = trunc i8 %xor to i1
107107
ret i1 %trunc
108108
}
109+
110+
define i1 @trunc_nuw_infere_false_for_icmp_ne_1(i8 %x) {
111+
; CHECK-LABEL: define i1 @trunc_nuw_infere_false_for_icmp_ne_1(
112+
; CHECK-SAME: i8 [[X:%.*]]) {
113+
; CHECK-NEXT: [[ICMP:%.*]] = icmp ne i8 [[X]], 1
114+
; CHECK-NEXT: br i1 [[ICMP]], label %[[IFTRUE:.*]], label %[[IFFALSE:.*]]
115+
; CHECK: [[IFTRUE]]:
116+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X]] to i1
117+
; CHECK-NEXT: ret i1 false
118+
; CHECK: [[IFFALSE]]:
119+
; CHECK-NEXT: ret i1 true
120+
;
121+
%icmp = icmp ne i8 %x, 1
122+
br i1 %icmp, label %iftrue, label %iffalse
123+
iftrue:
124+
%trunc = trunc nuw i8 %x to i1
125+
ret i1 %trunc
126+
iffalse:
127+
ret i1 true
128+
}
129+
130+
define i1 @neg_trunc_do_not_infere_false_for_icmp_ne_1(i8 %x) {
131+
; CHECK-LABEL: define i1 @neg_trunc_do_not_infere_false_for_icmp_ne_1(
132+
; CHECK-SAME: i8 [[X:%.*]]) {
133+
; CHECK-NEXT: [[ICMP:%.*]] = icmp ne i8 [[X]], 1
134+
; CHECK-NEXT: br i1 [[ICMP]], label %[[IFTRUE:.*]], label %[[IFFALSE:.*]]
135+
; CHECK: [[IFTRUE]]:
136+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X]] to i1
137+
; CHECK-NEXT: ret i1 [[TRUNC]]
138+
; CHECK: [[IFFALSE]]:
139+
; CHECK-NEXT: ret i1 true
140+
;
141+
%icmp = icmp ne i8 %x, 1
142+
br i1 %icmp, label %iftrue, label %iffalse
143+
iftrue:
144+
%trunc = trunc i8 %x to i1
145+
ret i1 %trunc
146+
iffalse:
147+
ret i1 true
148+
}

mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ static ConstantIntRanges inferDivURange(const ConstantIntRanges &lhs,
290290
DivisionFixupFn fixup) {
291291
const APInt &lhsMin = lhs.umin(), &lhsMax = lhs.umax(), &rhsMin = rhs.umin(),
292292
&rhsMax = rhs.umax();
293-
294-
if (!rhsMin.isZero()) {
293+
if (!rhsMin.isZero() && !rhsMax.isZero()) {
295294
auto udiv = [&fixup](const APInt &a,
296295
const APInt &b) -> std::optional<APInt> {
297296
return fixup(a, b, a.udiv(b));

mlir/test/Dialect/Arith/int-range-interface.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ func.func @ceil_divui(%arg0 : index) -> i1 {
224224
func.return %7 : i1
225225
}
226226

227+
// CHECK-LABEL: func @ceil_divui_by_zero_issue_131273
228+
// CHECK-NEXT: return
229+
func.func @ceil_divui_by_zero_issue_131273() {
230+
%0 = test.with_bounds {smax = 0 : i32, smin = -1 : i32, umax = 0 : i32, umin = -1 : i32} : i32
231+
%c7_i32 = arith.constant 7 : i32
232+
%1 = arith.ceildivui %c7_i32, %0 : i32
233+
return
234+
}
235+
227236
// CHECK-LABEL: func @ceil_divsi
228237
// CHECK: %[[ret:.*]] = arith.cmpi eq
229238
// CHECK: return %[[ret]]

0 commit comments

Comments
 (0)