[llvm] [GlobalISel] Check width of APInts in Reassoc PtrAdd combine (PR #84335)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 07:56:37 PST 2024


================
@@ -4653,7 +4653,8 @@ bool CombinerHelper::matchReassocFoldConstantsInSubTree(GPtrAdd &MI,
     return false;
 
   MatchInfo = [=, &MI](MachineIRBuilder &B) {
-    auto NewCst = B.buildConstant(MRI.getType(Src2Reg), *C1 + *C2);
+    auto NewCst = B.buildConstant(MRI.getType(Src2Reg),
+                                  C1->sextOrTrunc(C2->getBitWidth()) + *C2);
----------------
tschuett wrote:

`
unsigned BitWidth =
        std::max(C1->getBitWidth(), C2->getBitWidth());
`

see https://github.com/llvm/llvm-project/pull/82927

https://github.com/llvm/llvm-project/pull/84335


More information about the llvm-commits mailing list