[PATCH] D12866: [InstCombine] fold zexts and constants into a phi (PR24766)

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 19:29:39 PDT 2015


sanjoy added a subscriber: sanjoy.

================
Comment at: lib/Transforms/InstCombine/InstCombinePHI.cpp:399
@@ +398,3 @@
+      else if (Cast->getSrcTy() != FirstCast->getSrcTy() ||
+               Cast->getOpcode() != FirstCast->getOpcode() ||
+               !Cast->hasOneUse())
----------------
When will `Cast->getOpcode() != FirstCast->getOpcode()`?  Doesn't `Cast->getOpcode()` always have to be `Instruction::ZExt`?

================
Comment at: lib/Transforms/InstCombine/InstCombinePHI.cpp:416
@@ +415,3 @@
+  // performed here. It tries to replicate a cast in the phi operand's basic
+  // block to expose other folding opportunities. Thus, InstCombine will
+  // infinite loop without this check.
----------------
I'd structure this slightly different -- I'd have

```
SmallVector<Value *, 4> NewIncoming;
Type *NarrowType = nullptr;  // to keep track of what you're zext'ing from is same for all inputs

for (Value *V : Phi.incoming_value()) {
   // Check V here, and either append to NewIncoming or
   // return nullptr if you see something you cannot handle
   // (including constants)
}

// Create new PHI node with all the incoming values in NewIncoming
```

That'll keep most of the interesting logic in this function in one place.


http://reviews.llvm.org/D12866





More information about the llvm-commits mailing list