Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Sep 30, 2023

As I understand ICmp ConstantExpr are planned to be removed.

@topperc topperc requested a review from nikic September 30, 2023 05:35
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Sep 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 30, 2023

@llvm/pr-subscribers-llvm-analysis

Changes

As I understand ICmp ConstantExpr are planned to be removed.


Full diff: https://github.com/llvm/llvm-project/pull/67873.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+4-4)
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 40a8f6a155b23d2..5bdff48f79b4657 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3916,12 +3916,12 @@ static Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, // is non-negative then LHS <s RHS. case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_SGE: - return ConstantExpr::getICmp(ICmpInst::ICMP_SLT, C, - Constant::getNullValue(C->getType())); + return ConstantFoldCompareInstruction( + ICmpInst::ICMP_SLT, C, Constant::getNullValue(C->getType())); case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: - return ConstantExpr::getICmp(ICmpInst::ICMP_SGE, C, - Constant::getNullValue(C->getType())); + return ConstantFoldCompareInstruction( + ICmpInst::ICMP_SGE, C, Constant::getNullValue(C->getType())); } } } 
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ConstantFoldCompareInstOperands instead, which is DataLayout-aware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that matter here? C came from m_ImmConstant and we're comparing it to null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes no functional difference here, but you should never use the functions declared in llvm/IR/ConstantFold.h, only those in llvm/Analysis/ConstantFolding.h, which is the public API. We should maybe move the former into the detail namespace to make this clearer.

Copy link
Contributor

@nikic nikic Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or possibly we can move the ConstantFolder implementation out-of-line (if it causes no compile-time impact), because that's the only reason ConstantFold.h is a public header at all.

As I understand ICmp ConstantExpr are planned to be removed.
@topperc topperc force-pushed the pr/instsimplify-geticmp branch from d887d75 to 7cb5b6e Compare September 30, 2023 17:24
@topperc topperc merged commit a5686c2 into llvm:main Sep 30, 2023
@topperc topperc deleted the pr/instsimplify-geticmp branch September 30, 2023 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

3 participants