[PATCH] D99427: [LoopIdiomRecognize] Teach CTLZ/CTTZ idiom recognition to handle not being able to find a pre-loop check for the input being 0.

Aaron Puchert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 14:58:37 PDT 2022


aaronpuchert added inline comments.
Herald added a subscriber: StephenFan.
Herald added a project: All.


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:1811
 
   TcPhi->addIncoming(Count, Preheader);
   TcPhi->addIncoming(TcDec, Body);
----------------
Going with `NewCount` here shouldn't have unintended side effects, though we'd need to use a different `Ty` I think.


================
Comment at: llvm/test/Transforms/LoopIdiom/X86/ctlz.ll:294
+; ALL:       while.body:
+; ALL-NEXT:    [[TCPHI:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY_PREHEADER]] ], [ [[TCDEC:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT:    [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
----------------
craig.topper wrote:
> I think this needs to be TMP3 not TMP1.
Agreed. They differ for `ABS_N = 0` where `TMP1 = 0` but `TMP3 = 1`. With `TCPHI = 0` we get `TCDEC = -1` hence `TOBOOL = false` in the first iteration, so we don't exit as we should. In fact we'll eventually violate the `nsw` I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99427



More information about the llvm-commits mailing list