[PATCH] D114555: [ScalarEvolution] Add bailout to avoid zext of pointer.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 25 02:16:26 PST 2021


fhahn added a comment.

I'm wondering about:

> Not going to include a testcase; an IR testcase would be extremely complicated and fragile.

Below a reduced version from PR52594, which doesn't look too bad IMO. Is there anything in particular you think makes this test very fragile>

  target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
  
  define void @test(i8* %a, i8* %b, i64 %c) {
  entry:
    br label %loop.1.header
  
  loop.1.header:
    %iv.1 = phi i8* [ %a, %entry ], [ %iv.1.next, %loop.1.latch ]
    %cond = icmp eq i64 %c, 0
    br i1 %cond, label %loop.1.latch, label %exit
  
  loop.1.latch:
    %iv.1.next = getelementptr inbounds i8, i8* %iv.1, i32 1
    %ec = icmp eq i8* %iv.1.next, %b
    br i1 %ec, label %loop.2.ph, label %loop.1.header
  
  loop.2.ph:
    br label %loop.2
  
  loop.2:
    %iv.2 = phi i8* [ %iv.1.next, %loop.2.ph ], [ %iv.2.next, %loop.2 ]
    %iv.2.int = ptrtoint i8* %iv.2 to i32
    call void @wobble(i32 %iv.2.int)
    %ec.1 = icmp ult i8* %iv.2, %b
    %ec.1.trunc = and i1 %ec.1, 1
    %iv.2.next = getelementptr inbounds i8, i8* %iv.2, i32 1
    br i1 %ec.1.trunc, label %loop.2, label %exit
  
  exit:
    ret void
  }
  
  declare void @wobble(i32)



================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:10789
 
-    if (LHS->getType()->isPointerTy())
+    if (LHS->getType()->isPointerTy() || RHS->getType()->isPointerTy())
       return false;
----------------
can this be moved up before `if (!CmpInst::isSigned(FoundPred)....` and the pointer check dropped from the condition above?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114555/new/

https://reviews.llvm.org/D114555



More information about the llvm-commits mailing list