[llvm] [GIsel] Add combiner for constant-folding G_BITCAST (PR #193060)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 10:49:36 PDT 2026
================
@@ -1390,6 +1394,23 @@ def constant_fold_cast_op : GICombineRule<
[{ return Helper.matchConstantFoldCastOp(*${d}, ${matchinfo}); }]),
(apply [{ Helper.replaceInstWithConstant(*${d}, ${matchinfo}); }])>;
+
+def constant_fold_bitcast_of_const : BuildFnCombineRule<
+ (match (G_CONSTANT $src, $imm),
+ (G_BITCAST $d, $src):$root,
+ [{ return Helper.matchConstantFoldBitcast(
+ ${d}, ${imm}.getCImm()->getValue(), ${matchinfo}); }])>;
----------------
AlexMaclean wrote:
For a case where a constant integer is cast to a vector, It seems like folding that to a BUILD_VECTOR of constants adds more instructions and has the potential to introduce regressions if all-constant build vectors are not handled well elsewhere. Do you think it is a good idea to always canonicalize to this?
https://github.com/llvm/llvm-project/pull/193060
More information about the llvm-commits
mailing list