Skip to content

Commit 4779997

Browse files
committed
Merge commit '7f790f9a39e3' from llvm.org/release/17.x into stable/20230725
2 parents 63cf602 + 7f790f9 commit 4779997

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,19 @@ static Decomposition decompose(Value *V,
450450
return ResA;
451451
};
452452

453+
Type *Ty = V->getType()->getScalarType();
454+
if (Ty->isPointerTy() && !IsSigned) {
455+
if (auto *GEP = dyn_cast<GEPOperator>(V))
456+
return decomposeGEP(*GEP, Preconditions, IsSigned, DL);
457+
return V;
458+
}
459+
460+
// Don't handle integers > 64 bit. Our coefficients are 64-bit large, so
461+
// coefficient add/mul may wrap, while the operation in the full bit width
462+
// would not.
463+
if (!Ty->isIntegerTy() || Ty->getIntegerBitWidth() > 64)
464+
return V;
465+
453466
// Decompose \p V used with a signed predicate.
454467
if (IsSigned) {
455468
if (auto *CI = dyn_cast<ConstantInt>(V)) {
@@ -477,9 +490,6 @@ static Decomposition decompose(Value *V,
477490
return int64_t(CI->getZExtValue());
478491
}
479492

480-
if (auto *GEP = dyn_cast<GEPOperator>(V))
481-
return decomposeGEP(*GEP, Preconditions, IsSigned, DL);
482-
483493
Value *Op0;
484494
bool IsKnownNonNegative = false;
485495
if (match(V, m_ZExt(m_Value(Op0)))) {

llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ else:
9696
ret i1 false
9797
}
9898

99+
; TODO: This could be folded.
99100
define i1 @sub_decomp_i80(i80 %a) {
100101
; CHECK-LABEL: @sub_decomp_i80(
101102
; CHECK-NEXT: entry:
@@ -104,7 +105,8 @@ define i1 @sub_decomp_i80(i80 %a) {
104105
; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
105106
; CHECK: then:
106107
; CHECK-NEXT: [[SUB_1:%.*]] = sub nuw i80 [[A]], 1973801615886922022913
107-
; CHECK-NEXT: ret i1 true
108+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult i80 [[SUB_1]], 1346612317380797267967
109+
; CHECK-NEXT: ret i1 [[C_1]]
108110
; CHECK: else:
109111
; CHECK-NEXT: ret i1 false
110112
;
@@ -418,12 +420,12 @@ entry:
418420
ret i1 %res
419421
}
420422

421-
; FIXME: This is a miscompile.
422423
define i1 @pr68751(i128 %arg) {
423424
; CHECK-LABEL: @pr68751(
424425
; CHECK-NEXT: [[SHL1:%.*]] = shl nuw nsw i128 [[ARG:%.*]], 32
425426
; CHECK-NEXT: [[SHL2:%.*]] = shl nuw nsw i128 [[SHL1]], 32
426-
; CHECK-NEXT: ret i1 true
427+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i128 [[SHL2]], 0
428+
; CHECK-NEXT: ret i1 [[CMP]]
427429
;
428430
%shl1 = shl nuw nsw i128 %arg, 32
429431
%shl2 = shl nuw nsw i128 %shl1, 32

llvm/test/Transforms/ConstraintElimination/shl.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,8 @@ define i1 @shl_55() {
12771277
; CHECK-LABEL: @shl_55(
12781278
; CHECK-NEXT: entry:
12791279
; CHECK-NEXT: [[SHL_UB:%.*]] = shl nuw nsw i256 1, 55
1280-
; CHECK-NEXT: ret i1 true
1280+
; CHECK-NEXT: [[SHL_CMP:%.*]] = icmp uge i256 [[SHL_UB]], 1
1281+
; CHECK-NEXT: ret i1 [[SHL_CMP]]
12811282
;
12821283
entry:
12831284
%shl.ub = shl nuw nsw i256 1, 55

0 commit comments

Comments
 (0)