[PATCH] D145299: [InstCombine] Generate better code for std::bit_ceil
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 04:19:09 PDT 2023
nikic accepted this revision.
nikic added a comment.
LG
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3193-3227
+ // Match the operation that's used to compute CtlzOp from CommonAncestor. If
+ // a match is found, execute the operation on CR, update CR, and return true.
+ // Otherwise, return false.
+ auto MatchForward = [&](Value *CommonAncestor) {
+ const APInt *C = nullptr;
+ if (match(CtlzOp, m_Add(m_Specific(CommonAncestor), m_APInt(C)))) {
+ CR = CR.add(*C);
----------------
To clarify, this is what I meant.
================
Comment at: llvm/test/Transforms/InstCombine/bit_ceil.ll:164
-; CHECK-NEXT: [[UGT_INV:%.*]] = icmp ugt i32 [[X]], 1
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[UGT_INV]], i32 [[SHL]], i32 1
; CHECK-NEXT: ret i32 [[SEL]]
----------------
The order gets canonicalized here. You can use something like `icmp slt %x, 0` to avoid.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145299/new/
https://reviews.llvm.org/D145299
More information about the llvm-commits
mailing list