[llvm-branch-commits] [llvm] [InstCombine][JumpTableToSwitch] Make a helper for iterating global elements (PR #242822)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Nov 15 05:11:27 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ömer Sinan Ağacan (osa1)
<details>
<summary>Changes</summary>
Currently there are at least two folds/passes that read elements of a constant global:
- instcombine's `foldCmpLoadFromIndexedGlobal`
- jump-table-to-switch, when reading the functions from a jump table
and a third one is being written for simplifycfg in PR #<!-- -->229035.
The code to do that is not trivial, especially in its most general form. The two implementation above currently have different limitations, and PR #<!-- -->229035 has yet another buggy and limited implementation of it.
This PR adds a helper class `ConstGlobalIterator` that analyzes a load from a global and allows iterating the accessed elements. Current implementation is a copy of the instcombine's: that's the most general version we have today (though even that has limitations, e.g. it gives up when the stride is smaller than the load size).
The helper is used in the two use sites mentioned above, and it'll also be used in the WIP PR mentioned above.
Generalizing the helper will then handle more cases in instcombine, JTTS, and the new WIP simplifycfg fold with single update to the helper. Testing a single helper is also easier than 3 implementations of the same logic.
Note that the helper requires the indices to be in canonical index type, so JTTS only works with canonical index types now. This is not a problem in practice as JTTS only runs after instcombine.
---
Patch is 48.90 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/242822.diff
14 Files Affected:
- (modified) llvm/include/llvm/Analysis/Loads.h (+26)
- (modified) llvm/lib/Analysis/Loads.cpp (+78)
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+13-72)
- (modified) llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp (+21-42)
- (modified) llvm/test/Transforms/JumpTableToSwitch/basic.ll (+51-51)
- (modified) llvm/test/Transforms/JumpTableToSwitch/callee-type-mismatch.ll (+8-8)
- (modified) llvm/test/Transforms/JumpTableToSwitch/gep-flags.ll (+16-2)
- (modified) llvm/test/Transforms/JumpTableToSwitch/max_function_size.ll (+4-4)
- (modified) llvm/test/Transforms/JumpTableToSwitch/profile-no-guid-metadata.ll (+14-14)
- (modified) llvm/test/Transforms/JumpTableToSwitch/remarks.ll (+2-2)
- (modified) llvm/test/Transforms/JumpTableToSwitch/skip.ll (+38-39)
- (modified) llvm/test/Transforms/JumpTableToSwitch/stats.ll (+4-4)
- (modified) llvm/test/Transforms/JumpTableToSwitch/stride.ll (+6-6)
- (modified) llvm/test/Transforms/JumpTableToSwitch/struct.ll (+7-7)
``````````diff
diff --git a/llvm/include/llvm/Analysis/Loads.h b/llvm/include/llvm/Analysis/Loads.h
index 09fc8278606597..533dd53c5f1735 100644
--- a/llvm/include/llvm/Analysis/Loads.h
+++ b/llvm/include/llvm/Analysis/Loads.h
@@ -19,6 +19,7 @@
#include "llvm/IR/GEPNoWrapFlags.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
+#include <optional>
namespace llvm {
@@ -26,6 +27,7 @@ class BatchAAResults;
class AssumptionCache;
class DataLayout;
class DominatorTree;
+class IRBuilderBase;
class Instruction;
class LoadInst;
struct LoadStoreInstProperties;
@@ -238,6 +240,30 @@ struct LinearExpression {
/// multiple GEPs.
LLVM_ABI LinearExpression decomposeLinearExpression(const DataLayout &DL,
Value *Ptr);
+
+class ConstGlobalIterator {
+ const DataLayout &DL;
+ LinearExpression Expr;
+ uint64_t ArrayElementCount;
+ Constant *Init;
+ Type *EltTy;
+
+ ConstGlobalIterator(const DataLayout &DL, LinearExpression Expr,
+ uint64_t ArrayElementCount, Constant *Init, Type *EltTy)
+ : DL(DL), Expr(Expr), ArrayElementCount(ArrayElementCount), Init(Init),
+ EltTy(EltTy) {}
+
+public:
+ LLVM_ABI static std::optional<ConstGlobalIterator> fromLoadInst(LoadInst *LI);
+
+ LLVM_ABI Constant *elementAt(uint64_t Idx) const;
+
+ uint64_t size() const { return ArrayElementCount; }
+
+ const LinearExpression &expr() const { return Expr; }
+
+ LLVM_ABI Value *getIndex(IRBuilderBase &Builder) const;
+};
}
#endif
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 363b0f59e26064..06c27a8df3d030 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -22,6 +22,7 @@
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
@@ -1068,3 +1069,80 @@ LinearExpression llvm::decomposeLinearExpression(const DataLayout &DL,
return Expr;
}
+
+std::optional<ConstGlobalIterator>
+ConstGlobalIterator::fromLoadInst(LoadInst *LI) {
+ const DataLayout &DL = LI->getDataLayout();
+ Value *Ptr = LI->getPointerOperand();
+ auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(Ptr));
+ if (LI->isVolatile() || !GV || !GV->isConstant() ||
+ !GV->hasDefinitiveInitializer())
+ return std::nullopt;
+
+ Type *EltTy = LI->getType();
+ TypeSize EltSize = DL.getTypeStoreSize(EltTy);
+ if (EltSize.isScalable())
+ return std::nullopt;
+
+ LinearExpression Expr = decomposeLinearExpression(DL, Ptr);
+ if (!Expr.Index || Expr.BasePtr != GV || Expr.Offset.getBitWidth() > 64)
+ return std::nullopt;
+
+ Constant *Init = GV->getInitializer();
+ TypeSize GlobalSize = DL.getTypeAllocSize(Init->getType());
+
+ const APInt &Stride = Expr.Scale;
+ const APInt &ConstOffset = Expr.Offset;
+
+ // Allow an additional context offset, but only within the stride.
+ if (!ConstOffset.ult(Stride))
+ return std::nullopt;
+
+ // Don't handle overlapping loads for now.
+ if (!Stride.uge(EltSize.getFixedValue()))
+ return std::nullopt;
+
+ // - With nuw: `Idx * Stride` does not wrap and all strides are valid.
+ // - With nusw: `Idx * Stride` does not wrap as signed, and the following
+ // enumeration over ArrayElementCount is valid so long as the stride is
+ // positive.
+ // - Without nusw or nuw: `Idx * Stride` is computed modulo 2^N (see
+ // getIndex), and the masking in getIndex is only exact when the stride is
+ // a power of two.
+ bool StrideIsValid =
+ Expr.Flags.hasNoUnsignedWrap() ||
+ (Expr.Flags.hasNoUnsignedSignedWrap() ? !Stride.isNegative()
+ : Stride.isPowerOf2());
+ if (!StrideIsValid)
+ return std::nullopt;
+
+ uint64_t ArrayElementCount =
+ divideCeil((GlobalSize.getFixedValue() - ConstOffset.getZExtValue()),
+ Stride.getZExtValue());
+
+ return ConstGlobalIterator(DL, Expr, ArrayElementCount, Init, EltTy);
+}
+
+Constant *ConstGlobalIterator::elementAt(uint64_t Idx) const {
+ APInt Offset = Expr.Offset + (Expr.Scale * Idx);
+ return ConstantFoldLoadFromConst(Init, EltTy, Offset, DL);
+}
+
+Value *ConstGlobalIterator::getIndex(IRBuilderBase &Builder) const {
+ // If none of nusw (implied by inbounds) or nuw is present, Idx * Stride can
+ // overflow.
+ // Let's assume that Stride is 2 and the wanted value is at offset 0.
+ // Then, there are two possible values for Idx to match offset 0:
+ // 0x00..00, 0x80..00.
+ // Emitting 'icmp eq Idx, 0' isn't correct in this case because the
+ // comparison is false if Idx was 0x80..00.
+ // We need to erase the highest countr_zero(Stride) bits of Idx.
+ Value *Idx = Expr.Index;
+ unsigned Shift = Expr.Scale.countr_zero();
+ if (Expr.Flags.hasNoUnsignedWrap() || Expr.Flags.hasNoUnsignedSignedWrap() ||
+ Shift == 0)
+ return Idx;
+ Value *Mask = Constant::getAllOnesValue(Idx->getType());
+ Mask = Builder.CreateLShr(Mask, Shift);
+ return Builder.CreateAnd(Idx, Mask);
+}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 183206beb2dc34..b67c4735a9cf2e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -124,54 +124,13 @@ static bool isSignTest(ICmpInst::Predicate &Pred, const APInt &C) {
Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
LoadInst *LI, CmpPredicate Pred, Constant *RHSC, Instruction &CtxI,
ConstantInt *AndCst) {
- Value *Ptr = LI->getPointerOperand();
- auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(Ptr));
- if (LI->isVolatile() || !GV || !GV->isConstant() ||
- !GV->hasDefinitiveInitializer())
- return nullptr;
-
- Type *EltTy = LI->getType();
- TypeSize EltSize = DL.getTypeStoreSize(EltTy);
- if (EltSize.isScalable())
- return nullptr;
-
- LinearExpression Expr = decomposeLinearExpression(DL, Ptr);
- if (!Expr.Index || Expr.BasePtr != GV || Expr.Offset.getBitWidth() > 64)
- return nullptr;
-
- Constant *Init = GV->getInitializer();
- TypeSize GlobalSize = DL.getTypeAllocSize(Init->getType());
-
- Value *Idx = Expr.Index;
- const APInt &Stride = Expr.Scale;
- const APInt &ConstOffset = Expr.Offset;
-
- // Allow an additional context offset, but only within the stride.
- if (!ConstOffset.ult(Stride))
- return nullptr;
-
- // Don't handle overlapping loads for now.
- if (!Stride.uge(EltSize.getFixedValue()))
- return nullptr;
-
- // - With nuw: `Idx * Stride` does not wrap and all strides are valid.
- // - With nusw: `Idx * Stride` does not wrap as signed, and the following
- // enumeration over ArrayElementCount is valid so long as the stride is
- // positive.
- // - Without nusw or nuw: `Idx * Stride` is computed modulo 2^N (see MaskIdx
- // below), and the masking in MaskIdx below is only exact when the stride
- // is a power of two.
- bool StrideIsValid =
- Expr.Flags.hasNoUnsignedWrap() ||
- (Expr.Flags.hasNoUnsignedSignedWrap() ? !Stride.isNegative()
- : Stride.isPowerOf2());
- if (!StrideIsValid)
+ std::optional<ConstGlobalIterator> GlobalIter =
+ ConstGlobalIterator::fromLoadInst(LI);
+ if (!GlobalIter)
return nullptr;
// Don't blow up on huge arrays.
- uint64_t ArrayElementCount =
- divideCeil((GlobalSize.getFixedValue() - ConstOffset.getZExtValue()),
- Stride.getZExtValue());
+ const uint64_t ArrayElementCount = GlobalIter->size();
if (ArrayElementCount > CLOpts.maxarray_size)
return nullptr;
@@ -204,9 +163,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
uint64_t MagicBitvector = 0;
// Scan the array and see if one of our patterns matches.
- APInt Offset = ConstOffset;
- for (unsigned i = 0, e = ArrayElementCount; i != e; ++i, Offset += Stride) {
- Constant *Elt = ConstantFoldLoadFromConst(Init, EltTy, Offset, DL);
+ for (uint64_t i = 0; i < ArrayElementCount; i += 1) {
+ Constant *Elt = GlobalIter->elementAt(i);
if (!Elt)
return nullptr;
@@ -294,28 +252,11 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
// Now that we've scanned the entire array, emit our new comparison(s). We
// order the state machines in complexity of the generated code.
- // If none of nusw (implied by inbounds) or nuw is present, Idx * Stride can
- // overflow.
- // Let's assume that Stride is 2 and the wanted value is at offset 0.
- // Then, there are two possible values for Idx to match offset 0:
- // 0x00..00, 0x80..00.
- // Emitting 'icmp eq Idx, 0' isn't correct in this case because the
- // comparison is false if Idx was 0x80..00.
- // We need to erase the highest countTrailingZeros(Stride) bits of Idx.
- auto MaskIdx = [&](Value *Idx) {
- if (!Expr.Flags.hasNoUnsignedWrap() &&
- !Expr.Flags.hasNoUnsignedSignedWrap() && Stride.countr_zero() != 0) {
- Value *Mask = Constant::getAllOnesValue(Idx->getType());
- Mask = Builder.CreateLShr(Mask, Stride.countr_zero());
- Idx = Builder.CreateAnd(Idx, Mask);
- }
- return Idx;
- };
-
// If the comparison is only true for one or two elements, emit direct
// comparisons.
+ Value *Idx = GlobalIter->expr().Index;
if (SecondTrueElement != Overdefined) {
- Idx = MaskIdx(Idx);
+ Idx = GlobalIter->getIndex(Builder);
// None true -> false.
if (FirstTrueElement == Undefined)
return replaceInstUsesWith(CtxI, Builder.getFalse());
@@ -336,7 +277,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
// If the comparison is only false for one or two elements, emit direct
// comparisons.
if (SecondFalseElement != Overdefined) {
- Idx = MaskIdx(Idx);
+ Idx = GlobalIter->getIndex(Builder);
// None false -> true.
if (FirstFalseElement == Undefined)
return replaceInstUsesWith(CtxI, Builder.getTrue());
@@ -359,7 +300,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
// where it is true, emit the range check.
if (TrueRangeEnd != Overdefined) {
assert(TrueRangeEnd != FirstTrueElement && "Should emit single compare");
- Idx = MaskIdx(Idx);
+ Idx = GlobalIter->getIndex(Builder);
// Generate (i-FirstTrue) <u (TrueRangeEnd-FirstTrue+1).
if (FirstTrueElement) {
@@ -375,7 +316,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
// False range check.
if (FalseRangeEnd != Overdefined) {
assert(FalseRangeEnd != FirstFalseElement && "Should emit single compare");
- Idx = MaskIdx(Idx);
+ Idx = GlobalIter->getIndex(Builder);
// Generate (i-FirstFalse) >u (FalseRangeEnd-FirstFalse).
if (FirstFalseElement) {
Value *Offs = ConstantInt::getSigned(Idx->getType(), -FirstFalseElement);
@@ -399,10 +340,10 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
if (ArrayElementCount <= Idx->getType()->getIntegerBitWidth())
Ty = Idx->getType();
else
- Ty = DL.getSmallestLegalIntType(Init->getContext(), ArrayElementCount);
+ Ty = DL.getSmallestLegalIntType(RHSC->getContext(), ArrayElementCount);
if (Ty) {
- Idx = MaskIdx(Idx);
+ Idx = GlobalIter->getIndex(Builder);
Value *V = Builder.CreateIntCast(Idx, Ty, false);
V = Builder.CreateLShr(ConstantInt::get(Ty, MagicBitvector), V);
V = Builder.CreateAnd(ConstantInt::get(Ty, 1), V);
diff --git a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
index bcc9a696b9d114..8a418059c1e087 100644
--- a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
@@ -13,6 +13,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/IRBuilder.h"
@@ -49,47 +50,27 @@ static Function *getExpandableCallee(const ScalarOptions &Opts, Value *V,
}
static std::optional<JumpTable> parseJumpTable(const ScalarOptions &Opts,
- GetElementPtrInst *GEP,
- PointerType *PtrTy,
- FunctionType *CallFTy) {
- Constant *Ptr = dyn_cast<Constant>(GEP->getPointerOperand());
- if (!Ptr)
+ LoadInst *LI, PointerType *PtrTy,
+ FunctionType *CallFTy,
+ IRBuilderBase &Builder) {
+ std::optional<ConstGlobalIterator> GlobalIter =
+ ConstGlobalIterator::fromLoadInst(LI);
+ if (!GlobalIter)
return std::nullopt;
- GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr);
- if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
- return std::nullopt;
-
- Function &F = *GEP->getParent()->getParent();
- const DataLayout &DL = F.getDataLayout();
- const unsigned BitWidth =
- DL.getIndexSizeInBits(GEP->getPointerAddressSpace());
- SmallMapVector<Value *, APInt, 4> VariableOffsets;
- APInt ConstantOffset(BitWidth, 0);
- if (!GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset))
- return std::nullopt;
- if (VariableOffsets.size() != 1)
- return std::nullopt;
- // TODO: consider supporting more general patterns
- if (!ConstantOffset.isZero())
- return std::nullopt;
- APInt StrideBytes = VariableOffsets.front().second;
- const uint64_t JumpTableSizeBytes = GV->getGlobalSize(DL);
- if (JumpTableSizeBytes % StrideBytes.getZExtValue() != 0)
- return std::nullopt;
++NumEligibleJumpTables;
- const uint64_t N = JumpTableSizeBytes / StrideBytes.getZExtValue();
+
+ uint64_t N = GlobalIter->size();
if (N > Opts.jump_table_to_switch_size_threshold)
return std::nullopt;
- JumpTable JT;
- JT.Index = VariableOffsets.front().first;
- JT.Funcs.reserve(N);
+ Function &F = *LI->getParent()->getParent();
+
+ SmallVector<std::pair<uint64_t, Function *>, 10> Funcs;
+ Funcs.reserve(N);
+
for (uint64_t Index = 0; Index < N; ++Index) {
- // ConstantOffset is zero.
- APInt Offset = Index * StrideBytes;
- Constant *C =
- ConstantFoldLoadFromConst(GV->getInitializer(), PtrTy, Offset, DL);
+ Constant *C = GlobalIter->elementAt(Index);
if (!C)
return std::nullopt;
if ((isa<ConstantPointerNull>(C) &&
@@ -99,12 +80,13 @@ static std::optional<JumpTable> parseJumpTable(const ScalarOptions &Opts,
Function *Func = getExpandableCallee(Opts, C, CallFTy);
if (!Func)
return std::nullopt;
- JT.Funcs.push_back({Index, Func});
+ Funcs.push_back({Index, Func});
}
// Empty table, or only values that are UB when called
- if (JT.Funcs.empty())
+ if (Funcs.empty())
return std::nullopt;
- return JT;
+
+ return JumpTable{GlobalIter->getIndex(Builder), std::move(Funcs)};
}
static BasicBlock *
@@ -258,13 +240,10 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F,
// Skip atomic or volatile loads.
if (!L || !L->isSimple())
continue;
- auto *GEP = dyn_cast<GetElementPtrInst>(L->getPointerOperand());
- if (!GEP ||
- (!GEP->hasNoUnsignedWrap() && !GEP->hasNoUnsignedSignedWrap()))
- continue;
auto *PtrTy = dyn_cast<PointerType>(L->getType());
assert(PtrTy && "call operand must be a pointer");
- JT = parseJumpTable(Opts, GEP, PtrTy, Call->getFunctionType());
+ IRBuilder<> Builder(Call);
+ JT = parseJumpTable(Opts, L, PtrTy, Call->getFunctionType(), Builder);
}
if (!JT)
continue;
diff --git a/llvm/test/Transforms/JumpTableToSwitch/basic.ll b/llvm/test/Transforms/JumpTableToSwitch/basic.ll
index c6f59406f73378..9895ed2e1ace3d 100644
--- a/llvm/test/Transforms/JumpTableToSwitch/basic.ll
+++ b/llvm/test/Transforms/JumpTableToSwitch/basic.ll
@@ -37,14 +37,14 @@ define i32 @func1() !guid !1 {
ret i32 2
}
-define i32 @function_with_jump_table(i32 %index) {
+define i32 @function_with_jump_table(i64 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table(
-; CHECK-SAME: i32 [[INDEX:%.*]]) {
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 [[INDEX]]
+; CHECK-SAME: i64 [[INDEX:%.*]]) {
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i64 0, i64 [[INDEX]]
; CHECK-NEXT: [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
-; CHECK-NEXT: switch i32 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE:%.*]] [
-; CHECK-NEXT: i32 0, label [[CALL_0:%.*]]
-; CHECK-NEXT: i32 1, label [[CALL_1:%.*]]
+; CHECK-NEXT: switch i64 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE:%.*]] [
+; CHECK-NEXT: i64 0, label [[CALL_0:%.*]]
+; CHECK-NEXT: i64 1, label [[CALL_1:%.*]]
; CHECK-NEXT: ], !prof [[PROF2:![0-9]+]]
; CHECK: default.switch.case.unreachable:
; CHECK-NEXT: unreachable
@@ -59,26 +59,26 @@ define i32 @function_with_jump_table(i32 %index) {
; CHECK-NEXT: ret i32 [[TMP3]]
;
; THRESHOLD-0-LABEL: define i32 @function_with_jump_table(
-; THRESHOLD-0-SAME: i32 [[INDEX:%.*]]) {
-; THRESHOLD-0-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 [[INDEX]]
+; THRESHOLD-0-SAME: i64 [[INDEX:%.*]]) {
+; THRESHOLD-0-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i64 0, i64 [[INDEX]]
; THRESHOLD-0-NEXT: [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; THRESHOLD-0-NEXT: [[RESULT:%.*]] = call i32 [[FUNC_PTR]](), !prof [[PROF2:![0-9]+]]
; THRESHOLD-0-NEXT: ret i32 [[RESULT]]
;
- %gep = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 %index
+ %gep = getelementptr inbounds [2 x ptr], ptr @func_array, i64 0, i64 %index
%func_ptr = load ptr, ptr %gep
%result = call i32 %func_ptr(), !prof !2
ret i32 %result
}
-define i32 @basic_block_splitted_twice(i32 %index) {
+define i32 @basic_block_splitted_twice(i64 %index) {
; CHECK-LABEL: define i32 @basic_block_splitted_twice(
-; CHECK-SAME: i32 [[INDEX:%.*]]) {
-; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 [[INDEX]]
+; CHECK-SAME: i64 [[INDEX:%.*]]) {
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i64 0, i64 [[INDEX]]
; CHECK-NEXT: [[FUNC_PTR1:%.*]] = load ptr, ptr [[GEP1]], align 8
-; CHECK-NEXT: switch i32 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE:%.*]] [
-; CHECK-NEXT: i32 0, label [[CALL_0:%.*]]
-; CHECK-NEXT: i32 1, label [[CALL_1:%.*]]
+; CHECK-NEXT: switch i64 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE:%.*]] [
+; CHECK-NEXT: i64 0, label [[CALL_0:%.*]]
+; CHECK-NEXT: i64 1, label [[CALL_1:%.*]]
; CHECK-NEXT: ], !prof [[PROF3:![0-9]+]]
; CHECK: default.switch.case.unreachable:
; CHECK-NEXT: unreachable
@@ -90,11 +90,11 @@ define i32 @basic_block_splitted_twice(i32 %index) {
; CHECK-NEXT: br label [[DOTTAIL]]
; CHECK: .tail:
; CHECK-NEXT: [[TMP3:%.*]] = phi i32 [ [[TMP1]], [[CALL_0]] ], [ [[TMP2]], [[CALL_1]] ]
-; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 [[INDEX]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array, i64 0, i64 [[INDEX]]
; CHECK-NEXT: [[FUNC_PTR2:%.*]] = load ptr, ptr [[GEP2]], align 8
-; CHECK-NEXT: switch i32 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE1:%.*]] [
-; CHECK-NEXT: i32 0, label [[CALL_02:%.*]]
-; CHECK-NEXT: i32 1, label [[CALL_13:%.*]]
+; CHECK-NEXT: switch i64 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE1:%.*]] [
+; CHECK-NEXT: i64 0, label [[CALL_02:%.*]]
+; CHECK-NEXT: i64 1, label [[CALL_13:%.*]]
; CHECK-NEXT: ], !prof [[PROF3]]
; CHECK: default.switch.case.unreachable1:
; CHECK-NEXT: unreachable
@@ -110,20 +110,20 @@ define i32 @basic_block_splitted_twice(i32 %index) {
; CHECK-NEXT: ret i32 [[RESULT]]
;
; THRESHOLD-0-LABEL: define i32 @basic_block_splitted_twice(
-; THRESH...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/242822
More information about the llvm-branch-commits
mailing list