Skip to content

Commit c554589

Browse files
committed
- Update tests
- Modify constructor to take options
1 parent 4ae12ca commit c554589

27 files changed

+472
-108
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void initializeSafepointIRVerifierPass(PassRegistry &);
276276
void initializeSelectOptimizePass(PassRegistry &);
277277
void initializeScalarEvolutionWrapperPassPass(PassRegistry &);
278278
void initializeScalarizeMaskedMemIntrinLegacyPassPass(PassRegistry &);
279-
void initializeScalarizerLegacyPassPass(PassRegistry&);
279+
void initializeScalarizerLegacyPassPass(PassRegistry &);
280280
void initializeScavengerTestPass(PassRegistry &);
281281
void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &);
282282
void initializeSeparateConstOffsetFromGEPLegacyPassPass(PassRegistry &);

llvm/include/llvm/Transforms/Scalar/Scalarizer.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#define LLVM_TRANSFORMS_SCALAR_SCALARIZER_H
2020

2121
#include "llvm/IR/PassManager.h"
22-
#include "llvm/Pass.h"
2322
#include <optional>
2423

2524
namespace llvm {
2625

2726
class Function;
27+
class FunctionPass;
2828

2929
struct ScalarizerPassOptions {
3030
// These options correspond 1:1 to cl::opt options defined in
@@ -53,17 +53,8 @@ class ScalarizerPass : public PassInfoMixin<ScalarizerPass> {
5353
};
5454

5555
/// Create a legacy pass manager instance of the Scalarizer pass
56-
FunctionPass *createScalarizerPass();
57-
58-
class ScalarizerLegacyPass : public FunctionPass {
59-
public:
60-
static char ID;
61-
ScalarizerPassOptions Options;
62-
ScalarizerLegacyPass();
63-
bool runOnFunction(Function &F) override;
64-
void getAnalysisUsage(AnalysisUsage& AU) const override;
65-
};
66-
56+
FunctionPass *createScalarizerPass(
57+
const ScalarizerPassOptions &Options = ScalarizerPassOptions());
6758
}
6859

6960
#endif /* LLVM_TRANSFORMS_SCALAR_SCALARIZER_H */

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/InitializePasses.h"
2525
#include "llvm/Pass.h"
2626
#include "llvm/Support/ErrorHandling.h"
27-
#include "llvm/Transforms/Scalar/Scalarizer.h"
2827

2928
#define DEBUG_TYPE "dxil-op-lower"
3029

@@ -522,7 +521,6 @@ class DXILOpLoweringLegacy : public ModulePass {
522521
static char ID; // Pass identification.
523522
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
524523
AU.addRequired<DXILIntrinsicExpansionLegacy>();
525-
AU.addRequired<ScalarizerLegacyPass>();
526524
AU.addRequired<DXILResourceWrapperPass>();
527525
AU.addPreserved<DXILResourceWrapperPass>();
528526
}

llvm/lib/Target/DirectX/DirectXTargetMachine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include "llvm/CodeGen/MachineModuleInfo.h"
2727
#include "llvm/CodeGen/Passes.h"
2828
#include "llvm/CodeGen/TargetPassConfig.h"
29-
#include "llvm/InitializePasses.h"
3029
#include "llvm/IR/IRPrintingPasses.h"
3130
#include "llvm/IR/LegacyPassManager.h"
31+
#include "llvm/InitializePasses.h"
3232
#include "llvm/MC/MCSectionDXContainer.h"
3333
#include "llvm/MC/SectionKind.h"
3434
#include "llvm/MC/TargetRegistry.h"
@@ -86,7 +86,10 @@ class DirectXPassConfig : public TargetPassConfig {
8686
FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
8787
void addCodeGenPrepare() override {
8888
addPass(createDXILIntrinsicExpansionLegacyPass());
89-
addPass(createScalarizerPass());
89+
ScalarizerPassOptions DxilScalarOptions;
90+
// The only non-default option we need to set is ScalarizeLoadStore.
91+
DxilScalarOptions.ScalarizeLoadStore = true;
92+
addPass(createScalarizerPass(DxilScalarOptions));
9093
addPass(createDXILOpLoweringLegacyPass());
9194
addPass(createDXILFinalizeLinkageLegacyPass());
9295
addPass(createDXILTranslateMetadataLegacyPass());

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,25 @@ class ScalarizerVisitor : public InstVisitor<ScalarizerVisitor, bool> {
340340
const bool ScalarizeLoadStore;
341341
const unsigned ScalarizeMinBits;
342342
};
343+
344+
class ScalarizerLegacyPass : public FunctionPass {
345+
public:
346+
static char ID;
347+
ScalarizerPassOptions Options;
348+
ScalarizerLegacyPass() : FunctionPass(ID), Options() {}
349+
ScalarizerLegacyPass(const ScalarizerPassOptions &Options);
350+
bool runOnFunction(Function &F) override;
351+
void getAnalysisUsage(AnalysisUsage &AU) const override;
352+
};
353+
343354
} // end anonymous namespace
344355

345-
ScalarizerLegacyPass::ScalarizerLegacyPass() : FunctionPass(ID) {
346-
Options.ScalarizeVariableInsertExtract = true;
347-
Options.ScalarizeLoadStore = true;
348-
}
356+
ScalarizerLegacyPass::ScalarizerLegacyPass(const ScalarizerPassOptions &Options)
357+
: FunctionPass(ID), Options(Options) {}
349358

350-
void ScalarizerLegacyPass::getAnalysisUsage(AnalysisUsage& AU) const {
351-
AU.addRequired<DominatorTreeWrapperPass>();
352-
AU.addPreserved<DominatorTreeWrapperPass>();
359+
void ScalarizerLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const {
360+
AU.addRequired<DominatorTreeWrapperPass>();
361+
AU.addPreserved<DominatorTreeWrapperPass>();
353362
}
354363

355364
char ScalarizerLegacyPass::ID = 0;
@@ -440,8 +449,8 @@ bool ScalarizerLegacyPass::runOnFunction(Function &F) {
440449
return Impl.visit(F);
441450
}
442451

443-
FunctionPass *llvm::createScalarizerPass() {
444-
return new ScalarizerLegacyPass();
452+
FunctionPass *llvm::createScalarizerPass(const ScalarizerPassOptions &Options) {
453+
return new ScalarizerLegacyPass(Options);
445454
}
446455

447456
bool ScalarizerVisitor::visit(Function &F) {

llvm/test/CodeGen/DirectX/acos.ll

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for acos are generated for float and half.
44

5-
define noundef float @tan_float(float noundef %a) {
5+
define noundef float @acos_float(float noundef %a) {
66
entry:
77
; CHECK:call float @dx.op.unary.f32(i32 15, float %{{.*}})
88
%elt.acos = call float @llvm.acos.f32(float %a)
99
ret float %elt.acos
1010
}
1111

12-
define noundef half @tan_half(half noundef %a) {
12+
define noundef half @acos_half(half noundef %a) {
1313
entry:
1414
; CHECK:call half @dx.op.unary.f16(i32 15, half %{{.*}})
1515
%elt.acos = call half @llvm.acos.f16(half %a)
1616
ret half %elt.acos
1717
}
1818

19+
define noundef <4 x float> @acos_float4(<4 x float> noundef %a) {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 15, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 15, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 15, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 15, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.acos.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.acos.f16(half)
2038
declare float @llvm.acos.f32(float)
39+
declare <4 x float> @llvm.acos.v4f32(<4 x float>)

llvm/test/CodeGen/DirectX/asin.ll

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for asin are generated for float and half.
44

5-
define noundef float @tan_float(float noundef %a) {
5+
define noundef float @asin_float(float noundef %a) {
66
entry:
77
; CHECK:call float @dx.op.unary.f32(i32 16, float %{{.*}})
88
%elt.asin = call float @llvm.asin.f32(float %a)
99
ret float %elt.asin
1010
}
1111

12-
define noundef half @tan_half(half noundef %a) {
12+
define noundef half @asin_half(half noundef %a) {
1313
entry:
1414
; CHECK:call half @dx.op.unary.f16(i32 16, half %{{.*}})
1515
%elt.asin = call half @llvm.asin.f16(half %a)
1616
ret half %elt.asin
1717
}
1818

19+
define noundef <4 x float> @asin_float4(<4 x float> noundef %a) {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 16, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 16, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 16, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 16, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.asin.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.asin.f16(half)
2038
declare float @llvm.asin.f32(float)
39+
declare <4 x float> @llvm.asin.v4f32(<4 x float>)

llvm/test/CodeGen/DirectX/atan.ll

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for atan are generated for float and half.
44

5-
define noundef float @tan_float(float noundef %a) {
5+
define noundef float @atan_float(float noundef %a) {
66
entry:
77
; CHECK:call float @dx.op.unary.f32(i32 17, float %{{.*}})
88
%elt.atan = call float @llvm.atan.f32(float %a)
99
ret float %elt.atan
1010
}
1111

12-
define noundef half @tan_half(half noundef %a) {
12+
define noundef half @atan_half(half noundef %a) {
1313
entry:
1414
; CHECK:call half @dx.op.unary.f16(i32 17, half %{{.*}})
1515
%elt.atan = call half @llvm.atan.f16(half %a)
1616
ret half %elt.atan
1717
}
1818

19+
define noundef <4 x float> @atan_float4(<4 x float> noundef %a) {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 17, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 17, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 17, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 17, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.atan.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.atan.f16(half)
2038
declare float @llvm.atan.f32(float)
39+
declare <4 x float> @llvm.atan.v4f32(<4 x float>)

llvm/test/CodeGen/DirectX/ceil.ll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for ceil are generated for float and half.
44

@@ -16,5 +16,24 @@ entry:
1616
ret half %elt.ceil
1717
}
1818

19+
define noundef <4 x float> @ceil_float4(<4 x float> noundef %a) {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 28, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 28, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 28, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 28, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.ceil.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.ceil.f16(half)
2038
declare float @llvm.ceil.f32(float)
39+
declare <4 x float> @llvm.ceil.v4f32(<4 x float>)

llvm/test/CodeGen/DirectX/cos.ll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for cos are generated for float and half.
44

@@ -16,5 +16,24 @@ entry:
1616
ret half %elt.cos
1717
}
1818

19+
define noundef <4 x float> @cos_float4(<4 x float> noundef %a) #0 {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 12, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 12, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 12, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 12, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.cos.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.cos.f16(half)
2038
declare float @llvm.cos.f32(float)
39+
declare <4 x float> @llvm.cos.v4f32(<4 x float>)

llvm/test/CodeGen/DirectX/cosh.ll

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22

33
; Make sure dxil operation function calls for cosh are generated for float and half.
44

5-
define noundef float @tan_float(float noundef %a) {
5+
define noundef float @cosh_float(float noundef %a) {
66
entry:
77
; CHECK:call float @dx.op.unary.f32(i32 18, float %{{.*}})
88
%elt.cosh = call float @llvm.cosh.f32(float %a)
99
ret float %elt.cosh
1010
}
1111

12-
define noundef half @tan_half(half noundef %a) {
12+
define noundef half @cosh_half(half noundef %a) {
1313
entry:
1414
; CHECK:call half @dx.op.unary.f16(i32 18, half %{{.*}})
1515
%elt.cosh = call half @llvm.cosh.f16(half %a)
1616
ret half %elt.cosh
1717
}
1818

19+
define noundef <4 x float> @cosh_float4(<4 x float> noundef %a) #0 {
20+
entry:
21+
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22+
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 18, float [[ee0]])
23+
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24+
; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 18, float [[ee1]])
25+
; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26+
; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 18, float [[ee2]])
27+
; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28+
; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 18, float [[ee3]])
29+
; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32+
; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33+
%2 = call <4 x float> @llvm.cosh.v4f32(<4 x float> %a)
34+
ret <4 x float> %2
35+
}
36+
1937
declare half @llvm.cosh.f16(half)
2038
declare float @llvm.cosh.f32(float)
39+
declare <4 x float> @llvm.cosh.v4f32(<4 x float>)

0 commit comments

Comments
 (0)