[PATCH] D21246: [InstCombine] Add rule to fold away trunc of partial load

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 18:30:05 PDT 2016

sanjoy requested changes to this revision.
This revision now requires changes to proceed.

Comment at: lib/Analysis/Loads.cpp:385
@@ +384,3 @@
+      // If we support partial value forwarding to the load (PartialType is
+      // non-null): LI is from a part of the bits (known from PartialType)
+      // used by Load, return the value for those bits. The PartialType is from
It feels odd that we have to special-case `PartialType` this way.  I think a better design would be to introduce a new function `FindAvailableMemoryContents(Value *Ptr, Type *AccessTy ... < no PartialTy>)` (perhaps with a different name), and have this version of `FindAvailableLoadedValue` dispatch to `FindAvailableMemoryContents` one with `LI->getPointerOperand(), LI->getType()`.  `visitTrunc` can then call `FindAvailableMemoryContents` directly.

Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:588
@@ +587,3 @@
+    if (Value *AvailableVal = FindAvailableLoadedValue(
+            LI, LI->getParent(), BBI, DefMaxInstsToScan,
+            /* AA */ nullptr, /* AATags */ nullptr, DestTy))
Here if we have:

store i64 %x to %ptr
%val = load i64* %ptr
%val.tr = trunc i64 %val to i32

won't we have a type mismatch and try to replace `%val.tr` with `%x`?


More information about the llvm-commits mailing list