[llvm] [ConstantFold][RFC] Refactor getBinOpAbsorber function (PR #109736)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 06:10:00 PDT 2024
================
@@ -729,13 +729,15 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
// Neither constant should be UndefValue, unless these are vector constants.
assert((!HasScalarUndefOrScalableVectorUndef) && "Unexpected UndefValue");
+ Constant *Absorber = ConstantExpr::getBinOpAbsorber(
+ Opcode, C1->getType(), /*AllowLHSAbsorber*/ true);
+
// Handle simplifications when the RHS is a constant int.
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
+ if (C2 == Absorber)
+ return C2;
----------------
nikic wrote:
This looks incorrect. You are using the Absorber value with AllowLHSAbsorber=true and then using it to check the RHS. This means that for example `X << 0` could get incorrectly folded to `0`, no? I think the only reason this works out here is by accident, because this case is already handled by the identity logic earlier.
https://github.com/llvm/llvm-project/pull/109736
More information about the llvm-commits
mailing list