[llvm] 4905bca - [ConstantFolding] Check return value of ConstantFoldInstOperandsImpl()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 4 05:20:09 PDT 2022
Author: Nikita Popov
Date: 2022-07-04T14:19:59+02:00
New Revision: 4905bcac00e6588bc82e51973dcac7b7a5361c94
URL: https://github.com/llvm/llvm-project/commit/4905bcac00e6588bc82e51973dcac7b7a5361c94
DIFF: https://github.com/llvm/llvm-project/commit/4905bcac00e6588bc82e51973dcac7b7a5361c94.diff
LOG: [ConstantFolding] Check return value of ConstantFoldInstOperandsImpl()
This operation is fallible, but ConstantFoldConstantImpl() is not.
If we fail to fold, we should simply return the original expression.
I don't think this can cause any issues right now, but it becomes
a problem if once make ConstantFoldInstOperandsImpl() not create a
constant expression for everything it possibly could.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a810418450520..b708b71192036 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1142,8 +1142,12 @@ ConstantFoldConstantImpl(const Constant *C, const DataLayout &DL,
Ops.push_back(NewC);
}
- if (auto *CE = dyn_cast<ConstantExpr>(C))
- return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI);
+ if (auto *CE = dyn_cast<ConstantExpr>(C)) {
+ if (Constant *Res =
+ ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI))
+ return Res;
+ return const_cast<Constant *>(C);
+ }
assert(isa<ConstantVector>(C));
return ConstantVector::get(Ops);
More information about the llvm-commits
mailing list