[llvm] [GlobalISel] Constant-fold G_PTR_ADD with different type sizes (PR #81473)
Piotr Sobczak via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 04:20:59 PST 2024
================
@@ -660,8 +660,15 @@ std::optional<APInt> llvm::ConstantFoldBinOp(unsigned Opcode,
default:
break;
case TargetOpcode::G_ADD:
- case TargetOpcode::G_PTR_ADD:
return C1 + C2;
+ case TargetOpcode::G_PTR_ADD: {
+ // Types can be of different width here.
+ if (C1.getBitWidth() < C2.getBitWidth())
+ return C1.zext(C1.getBitWidth()) + C2;
----------------
piotrAMD wrote:
C2.getBitWidth() ?
https://github.com/llvm/llvm-project/pull/81473
More information about the llvm-commits
mailing list