Skip to content

Commit 8a92def

Browse files
author
v01dxyz
committed
Fix eliminateTrunc
Out of loop, an IV user is loop invariant. Using L->isLoopInvariant is no more valid to distinguish which operand is the loop-constant one from the IV user.
1 parent db8fb22 commit 8a92def

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) {
554554
};
555555
// Replace all comparisons against trunc with comparisons against IV.
556556
for (auto *ICI : ICmpUsers) {
557-
bool IsSwapped = L->isLoopInvariant(ICI->getOperand(0));
557+
bool IsSwapped = ICI->getOperand(0) != TI;
558558
auto *Op1 = IsSwapped ? ICI->getOperand(0) : ICI->getOperand(1);
559559
IRBuilder<> Builder(ICI);
560560
Value *Ext = nullptr;

llvm/test/Transforms/IndVarSimplify/out_of_loop_eliminate_truncate.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ define dso_local noundef zeroext i1 @matchSimpleRecurrence(
2424
; CHECK-NEXT: [[CMP_NOT17_LCSSA:%.*]] = phi i1 [ [[CMP_NOT17]], %[[FOR_BODY]] ]
2525
; CHECK-NEXT: [[I_016_LCSSA_WIDE:%.*]] = phi i64 [ [[INDVARS_IV]], %[[FOR_BODY]] ]
2626
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi ptr [ [[TMP0]], %[[FOR_BODY]] ]
27-
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 poison to i64
28-
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[I_016_LCSSA_WIDE]], [[ZEXT]]
27+
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[I_016_LCSSA_WIDE]], 0
2928
; CHECK-NEXT: [[IDXPROM1:%.*]] = zext i1 [[TMP1]] to i64
3029
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds ptr, ptr [[P]], i64 [[IDXPROM1]]
3130
; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[ARRAYIDX2]], align 8
@@ -99,7 +98,7 @@ define i1 @check_size_str(ptr %str, i32 %str.size, i32 %n) {
9998
; CHECK-NEXT: br i1 [[OR]], label %[[EXIT:.*]], label %[[LOOP]]
10099
; CHECK: [[EXIT]]:
101100
; CHECK-NEXT: [[I_LCSSA:%.*]] = phi i64 [ [[I]], %[[LOOP]] ]
102-
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 poison to i64
101+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[N]] to i64
103102
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i64 [[I_LCSSA]], [[ZEXT]]
104103
; CHECK-NEXT: ret i1 [[TMP0]]
105104
;

0 commit comments

Comments
 (0)