[PATCH] D34141: [X86] Recognize constant arrays with special values and replace loads from it with subtract and shift instructions, which then will be replaced by X86 BZHI machine instruction.

Ayman Musa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 03:50:26 PST 2017


aymanmus marked an inline comment as done.
aymanmus added inline comments.


================
Comment at: lib/Target/X86/X86ISelLowering.cpp:32521
+    if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(MemOp)) {
+      if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0))) {
+        if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
----------------
m_zuckerman wrote:
> Can you explain why the element must to be a global variable? 
Clang will always hoist a local constant array to be global in LLVM IR.


================
Comment at: lib/Target/X86/X86ISelLowering.cpp:32526
+          Type *Ty = Init->getType();
+          if (!isa<ConstantDataArray>(Init) ||
+              !Ty->getArrayElementType()->isIntegerTy() ||
----------------
m_zuckerman wrote:
>   # please clarify this if (add comments) 
>   # Why you need also the isa<ConstantDataArray>(Init) ,is it not the same as GV->isConstant()? 
The second condition makes sure that it is a constant data *array*. GV->isConstant does not.


================
Comment at: lib/Target/X86/X86ISelLowering.cpp:32548
+
+          // Do the transformation (For 32-bit type):
+          // -> (and (load arr[idx]), inp)
----------------
m_zuckerman wrote:
> What about 64 bit? 
It's only an example for the 32-bit case, the same happens for 64 as well.


https://reviews.llvm.org/D34141





More information about the llvm-commits mailing list