[llvm] 3b73892 - [SimpleLoopUnswitch] Do not try to inject pointer conditions. PR62058

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 06:38:37 PDT 2023


Author: Max Kazantsev
Date: 2023-04-12T20:38:17+07:00
New Revision: 3b73892b439e69f4c490a5d932f14808885b5241

URL: https://github.com/llvm/llvm-project/commit/3b73892b439e69f4c490a5d932f14808885b5241
DIFF: https://github.com/llvm/llvm-project/commit/3b73892b439e69f4c490a5d932f14808885b5241.diff

LOG: [SimpleLoopUnswitch] Do not try to inject pointer conditions. PR62058

As shown in https://github.com/llvm/llvm-project/issues/62058, canonicalication
may fail with pointer types (and basically this transform is not expected to
work with pointers).

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    llvm/test/Transforms/SimpleLoopUnswitch/pr62058.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 1e2c9c9ebcb8c..e78c7a88ea8e2 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -3167,6 +3167,8 @@ static bool collectUnswitchCandidatesWithInjections(
     if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
                           m_BasicBlock(IfTrue), m_BasicBlock(IfFalse))))
       continue;
+    if (!LHS->getType()->isIntegerTy())
+      continue;
     canonicalizeForInvariantConditionInjection(Pred, LHS, RHS, IfTrue, IfFalse,
                                                L);
     if (!shouldTryInjectInvariantCondition(Pred, LHS, RHS, IfTrue, IfFalse, L))

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/pr62058.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pr62058.ll
index 708d4c267ae2b..5b5502fba1258 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/pr62058.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/pr62058.ll
@@ -1,11 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
 ; RUN: opt < %s -simple-loop-unswitch-inject-invariant-conditions=true -passes='loop(simple-loop-unswitch<nontrivial>)' -S | FileCheck %s
-; REQUIRES: asserts
-; XFAIL: *
 
 @global = external dso_local local_unnamed_addr global i64, align 8
 
 define dso_local void @test() local_unnamed_addr #0 {
-; CHECK-LABEL: test
+; CHECK-LABEL: define dso_local void @test() local_unnamed_addr {
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br label [[BB1:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call noundef ptr @widget()
+; CHECK-NEXT:    [[ICMP:%.*]] = icmp slt ptr [[CALL]], null
+; CHECK-NEXT:    br i1 [[ICMP]], label [[BB2:%.*]], label [[BB1]]
+; CHECK:       bb2:
+; CHECK-NEXT:    ret void
+;
 bb:
   br label %bb1
 


        


More information about the llvm-commits mailing list