Skip to content

Commit 94ecfb0

Browse files
committed
LICM: address review
1 parent 85de949 commit 94ecfb0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,9 +2458,10 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
24582458
return false;
24592459

24602460
// Everything is fine, we can do the transform.
2461-
bool UseMin = ICmpInst::isLT(P1) || ICmpInst::isLE(P1);
2461+
bool UseMin = ICmpInst::isLT(*MatchingPred) || ICmpInst::isLE(*MatchingPred);
24622462
assert(
2463-
(UseMin || ICmpInst::isGT(P1) || ICmpInst::isGE(P1)) &&
2463+
(UseMin || ICmpInst::isGT(*MatchingPred) ||
2464+
ICmpInst::isGE(*MatchingPred)) &&
24642465
"Relational predicate is either less (or equal) or greater (or equal)!");
24652466
Intrinsic::ID id = ICmpInst::isSigned(*MatchingPred)
24662467
? (UseMin ? Intrinsic::smin : Intrinsic::smax)
@@ -2475,9 +2476,10 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
24752476
if (isa<SelectInst>(I))
24762477
RHS2 = Builder.CreateFreeze(RHS2, RHS2->getName() + ".fr");
24772478
Value *NewRHS = Builder.CreateBinaryIntrinsic(
2478-
id, RHS1, RHS2, nullptr, StringRef("invariant.") +
2479-
(ICmpInst::isSigned(P1) ? "s" : "u") +
2480-
(UseMin ? "min" : "max"));
2479+
id, RHS1, RHS2, nullptr,
2480+
StringRef("invariant.") +
2481+
(ICmpInst::isSigned(*MatchingPred) ? "s" : "u") +
2482+
(UseMin ? "min" : "max"));
24812483
Builder.SetInsertPoint(&I);
24822484
ICmpInst::Predicate P = *MatchingPred;
24832485
if (Inverse)

llvm/test/Transforms/LICM/min_max.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ exit:
245245
define i32 @test_sgt_samesign(i32 %start, i32 %inv_1, i32 %inv_2) {
246246
; CHECK-LABEL: @test_sgt_samesign(
247247
; CHECK-NEXT: entry:
248-
; CHECK-NEXT: [[INVARIANT_UMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[INV_1:%.*]], i32 [[INV_2:%.*]])
248+
; CHECK-NEXT: [[INVARIANT_SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[INV_1:%.*]], i32 [[INV_2:%.*]])
249249
; CHECK-NEXT: br label [[LOOP:%.*]]
250250
; CHECK: loop:
251251
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
252-
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sgt i32 [[IV]], [[INVARIANT_UMAX]]
252+
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sgt i32 [[IV]], [[INVARIANT_SMAX]]
253253
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
254254
; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
255255
; CHECK: exit:
@@ -304,13 +304,13 @@ exit:
304304
define i32 @test_sge_samesign(i32 %start, i32 %inv_1, i32 %inv_2) {
305305
; CHECK-LABEL: @test_sge_samesign(
306306
; CHECK-NEXT: entry:
307-
; CHECK-NEXT: [[INV_1:%.*]] = call i32 @llvm.smax.i32(i32 [[INV_3:%.*]], i32 [[INV_2:%.*]])
307+
; CHECK-NEXT: [[INVARIANT_SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[INV_1:%.*]], i32 [[INV_2:%.*]])
308308
; CHECK-NEXT: br label [[LOOP:%.*]]
309309
; CHECK: loop:
310310
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
311-
; CHECK-NEXT: [[CMP_1:%.*]] = icmp sge i32 [[IV]], [[INV_1]]
311+
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sge i32 [[IV]], [[INVARIANT_SMAX]]
312312
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
313-
; CHECK-NEXT: br i1 [[CMP_1]], label [[LOOP]], label [[EXIT:%.*]]
313+
; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
314314
; CHECK: exit:
315315
; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[LOOP]] ]
316316
; CHECK-NEXT: ret i32 [[IV_LCSSA]]

0 commit comments

Comments
 (0)