aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-06-30 12:16:57 +0200
committerNikita Popov <npopov@redhat.com>2022-06-30 12:18:15 +0200
commit0445c340ff48b9ba53e69933cef0af703bb5ea0f (patch)
tree0408b55b820cc53d267d7699466429b962c75124 /llvm/lib/Analysis/ConstantFolding.cpp
parent364673dbe783164e94ba801399a3587290b8cc66 (diff)
downloadllvm-0445c340ff48b9ba53e69933cef0af703bb5ea0f.zip
llvm-0445c340ff48b9ba53e69933cef0af703bb5ea0f.tar.gz
llvm-0445c340ff48b9ba53e69933cef0af703bb5ea0f.tar.bz2
[ConstantFold] Support loads in ConstantFoldInstOperands()
This allows all constant folding to happen through a single function, without requiring special handling for loads at each call-site. This may not be NFC because some callers currently don't do that special handling.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index f5da963..01092b4 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1098,6 +1098,12 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
case Instruction::ShuffleVector:
return ConstantExpr::getShuffleVector(
Ops[0], Ops[1], cast<ShuffleVectorInst>(InstOrCE)->getShuffleMask());
+ case Instruction::Load: {
+ const auto *LI = dyn_cast<LoadInst>(InstOrCE);
+ if (LI->isVolatile())
+ return nullptr;
+ return ConstantFoldLoadFromConstPtr(Ops[0], LI->getType(), DL);
+ }
}
}
@@ -1188,12 +1194,6 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
Ops.push_back(Op);
}
- if (const auto *LI = dyn_cast<LoadInst>(I)) {
- if (LI->isVolatile())
- return nullptr;
- return ConstantFoldLoadFromConstPtr(Ops[0], LI->getType(), DL);
- }
-
return ConstantFoldInstOperands(I, Ops, DL, TLI);
}