[llvm] fc128e1 - [LICM] Do not hoist min/max for pointer types
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 13 00:12:50 PDT 2023
Author: Max Kazantsev
Date: 2023-03-13T14:12:21+07:00
New Revision: fc128e126bcd6ca2723e74282601ef76f705489f
URL: https://github.com/llvm/llvm-project/commit/fc128e126bcd6ca2723e74282601ef76f705489f
DIFF: https://github.com/llvm/llvm-project/commit/fc128e126bcd6ca2723e74282601ef76f705489f.diff
LOG: [LICM] Do not hoist min/max for pointer types
umin and similar intrinsics are not defined for them.
Added:
Modified:
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/min_max.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 68749502c58d4..d0f7dc21c98a5 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2427,6 +2427,8 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
Value *&LHS, Value *&RHS) {
if (!match(C, m_OneUse(m_ICmp(P, m_Value(LHS), m_Value(RHS)))))
return false;
+ if (!LHS->getType()->isIntegerTy())
+ return false;
if (!ICmpInst::isRelational(P))
return false;
if (L.isLoopInvariant(LHS)) {
diff --git a/llvm/test/Transforms/LICM/min_max.ll b/llvm/test/Transforms/LICM/min_max.ll
index d9710daa1645f..9cd440968d72e 100644
--- a/llvm/test/Transforms/LICM/min_max.ll
+++ b/llvm/test/Transforms/LICM/min_max.ll
@@ -31,6 +31,37 @@ exit:
ret i32 %iv
}
+; Do not optimize: pointer types.
+define ptr @test_ult_ptr_neg(ptr %start, ptr %inv_1, ptr %inv_2) {
+; CHECK-LABEL: @test_ult_ptr_neg(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi ptr [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[CMP_1:%.*]] = icmp ult ptr [[IV]], [[INV_1:%.*]]
+; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult ptr [[IV]], [[INV_2:%.*]]
+; CHECK-NEXT: [[LOOP_COND:%.*]] = and i1 [[CMP_1]], [[CMP_2]]
+; CHECK-NEXT: [[IV_NEXT]] = getelementptr i32, ptr [[IV]], i64 4
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi ptr [ [[IV]], [[LOOP]] ]
+; CHECK-NEXT: ret ptr [[IV_LCSSA]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi ptr [%start, %entry], [%iv.next, %loop]
+ %cmp_1 = icmp ult ptr %iv, %inv_1
+ %cmp_2 = icmp ult ptr %iv, %inv_2
+ %loop_cond = and i1 %cmp_1, %cmp_2
+ %iv.next = getelementptr i32, ptr %iv, i64 4
+ br i1 %loop_cond, label %loop, label %exit
+
+exit:
+ ret ptr %iv
+}
+
; turn to %iv <=u umin(inv_1, inv_2) and hoist it out of loop.
define i32 @test_ule(i32 %start, i32 %inv_1, i32 %inv_2) {
; CHECK-LABEL: @test_ule(
More information about the llvm-commits
mailing list