[llvm] [DAGCombiner] Add some very basic folds for ADDRSPACECAST (PR #127733)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 10:16:59 PST 2025
================
@@ -16054,6 +16056,25 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
return SDValue();
}
+SDValue DAGCombiner::visitADDRSPACECAST(SDNode *N) {
+ auto *ASCN1 = cast<AddrSpaceCastSDNode>(N);
+
+ if (auto *ASCN2 = dyn_cast<AddrSpaceCastSDNode>(ASCN1->getOperand(0))) {
+ assert(ASCN2->getDestAddressSpace() == ASCN1->getSrcAddressSpace());
+
+ // Fold asc[B -> A](asc[A -> B](x)) -> x
+ if (ASCN1->getDestAddressSpace() == ASCN2->getSrcAddressSpace())
+ return ASCN2->getOperand(0);
+
+ // Fold asc[B -> C](asc[A -> B](x)) -> asc[A -> C](x)
----------------
Artem-B wrote:
> if the pointer is dereferenceable, the cast is assumed reversible
In my example above, each individual cast is reversible, but that does not guarantee transitivity.
https://github.com/llvm/llvm-project/pull/127733
More information about the llvm-commits
mailing list