Skip to content

Commit 62ae7d9

Browse files
committed
[LoopUnroll] Fix missing sign extension
For integers larger than 64-bit, this would zero-extend a -1 value, instead of sign-extending it. Fixes #80289.
1 parent f7b05e0 commit 62ae7d9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
776776
!isGuaranteedNotToBeUndefOrPoison(TripCount, AC, PreHeaderBR, DT)) {
777777
TripCount = B.CreateFreeze(TripCount);
778778
BECount =
779-
B.CreateAdd(TripCount, ConstantInt::get(TripCount->getType(), -1));
779+
B.CreateAdd(TripCount, Constant::getAllOnesValue(TripCount->getType()));
780780
} else {
781781
// If we don't need to freeze, use SCEVExpander for BECount as well, to
782782
// allow slightly better value reuse.

llvm/test/Transforms/LoopUnroll/runtime-i128.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define void @test(i128 %n, i128 %m) {
88
; CHECK-SAME: i128 [[N:%.*]], i128 [[M:%.*]]) {
99
; CHECK-NEXT: entry:
1010
; CHECK-NEXT: [[TMP0:%.*]] = freeze i128 [[N]]
11-
; CHECK-NEXT: [[TMP1:%.*]] = add i128 [[TMP0]], 18446744073709551615
11+
; CHECK-NEXT: [[TMP1:%.*]] = add i128 [[TMP0]], -1
1212
; CHECK-NEXT: [[XTRAITER:%.*]] = and i128 [[TMP0]], 7
1313
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i128 [[TMP1]], 7
1414
; CHECK-NEXT: br i1 [[TMP2]], label [[EXIT_UNR_LCSSA:%.*]], label [[ENTRY_NEW:%.*]]

0 commit comments

Comments
 (0)