[PATCH] D145890: [InstCombine] Generate better code for std::bit_floor from libstdc++

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 9 15:22:40 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3325
+  return cast<Instruction>(
+      Builder.CreateLShr(ConstantInt::get(NType, ShiftedBit), NewCTLZ));
+}
----------------
kazu wrote:
> goldstein.w.n wrote:
> > This can be exact:
> > https://alive2.llvm.org/ce/z/Enurag
> > 
> > I think:
> > 
> > ```
> > BinaryOperator *BO = BinaryOperator::CreateLShr(ConstantInt::get(NType, ShiftedBit), NewCTLZ);
> >   BO->setIsExact();
> >   return BO;
> > ``` 
> > 
> > Should work.
> If I do this, I get:
> 
> ```
> llvm/include/llvm/Transforms/Utils/InstructionWorklist.h:60: void llvm::InstructionWorklist::push(llvm::Instruction *): Assertion `I->getParent() && "Instruction not inserted yet?"' failed.
> ```
> 
> 
> If I do this, I get:
> 
> ```
> llvm/include/llvm/Transforms/Utils/InstructionWorklist.h:60: void llvm::InstructionWorklist::push(llvm::Instruction *): Assertion `I->getParent() && "Instruction not inserted yet?"' failed.
> ```
> 
> 

Ahh, because you use replaceoperand below I believe.

Then just `cast` what you are turning to a `BinaryOperator` and `setIsExact`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145890



More information about the llvm-commits mailing list