Skip to content

Commit 81def81

Browse files
authored
Merge branch 'llvm:main' into feature/extend-macros
2 parents 339a552 + 2e9f869 commit 81def81

19 files changed

+1322
-5
lines changed

llvm/docs/Passes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ variables with initializers are marked as internal.
543543
An interprocedural variant of :ref:`Sparse Conditional Constant Propagation
544544
<passes-sccp>`.
545545

546+
``ir-normalizer``: Transforms IR into a normal form that's easier to diff
547+
----------------------------------------------------------------------------
548+
549+
This pass aims to transform LLVM Modules into a normal form by reordering and
550+
renaming instructions while preserving the same semantics. The normalizer makes
551+
it easier to spot semantic differences while diffing two modules which have
552+
undergone two different passes.
553+
546554
``jump-threading``: Jump Threading
547555
----------------------------------
548556

llvm/docs/ReleaseNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ point (e.g. maybe you would like to give an example of the
4242
functionality, or simply have a lot to talk about), see the comment below
4343
for adding a new subsection. -->
4444

45+
* Added a new IRNormalizer pass which aims to transform LLVM modules into
46+
a normal form by reordering and renaming instructions while preserving the
47+
same semantics. The normalizer makes it easier to spot semantic differences
48+
when diffing two modules which have undergone different passes.
49+
4550
* ...
4651

4752
<!-- If you would like to document a larger change, then you can add a
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef LLVM_TRANSFORMS_UTILS_IRNORMALIZER_H
2+
#define LLVM_TRANSFORMS_UTILS_IRNORMALIZER_H
3+
4+
#include "llvm/IR/PassManager.h"
5+
6+
namespace llvm {
7+
8+
/// IRNormalizer aims to transform LLVM IR into normal form.
9+
struct IRNormalizerPass : public PassInfoMixin<IRNormalizerPass> {
10+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) const;
11+
};
12+
13+
} // namespace llvm
14+
15+
#endif // LLVM_TRANSFORMS_UTILS_IRNORMALIZER_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@
306306
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
307307
#include "llvm/Transforms/Utils/FixIrreducible.h"
308308
#include "llvm/Transforms/Utils/HelloWorld.h"
309+
#include "llvm/Transforms/Utils/IRNormalizer.h"
309310
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
310311
#include "llvm/Transforms/Utils/InstructionNamer.h"
311-
#include "llvm/Transforms/Utils/Instrumentation.h"
312312
#include "llvm/Transforms/Utils/LCSSA.h"
313313
#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
314314
#include "llvm/Transforms/Utils/LoopSimplify.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ FUNCTION_PASS("move-auto-init", MoveAutoInitPass())
416416
FUNCTION_PASS("nary-reassociate", NaryReassociatePass())
417417
FUNCTION_PASS("newgvn", NewGVNPass())
418418
FUNCTION_PASS("no-op-function", NoOpFunctionPass())
419+
FUNCTION_PASS("normalize", IRNormalizerPass())
419420
FUNCTION_PASS("objc-arc", ObjCARCOptPass())
420421
FUNCTION_PASS("objc-arc-contract", ObjCARCContractPass())
421422
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14381438
}
14391439

14401440
// Custom-legalize bitcasts from fixed-length vectors to scalar types.
1441-
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32, MVT::i64},
1442-
Custom);
1441+
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32}, Custom);
1442+
if (Subtarget.is64Bit())
1443+
setOperationAction(ISD::BITCAST, MVT::i64, Custom);
14431444
if (Subtarget.hasStdExtZfhminOrZhinxmin())
14441445
setOperationAction(ISD::BITCAST, MVT::f16, Custom);
14451446
if (Subtarget.hasStdExtZfbfmin())
@@ -6422,7 +6423,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
64226423
SDValue NewOp0 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, Op0);
64236424
return DAG.getNode(RISCVISD::FMV_W_X_RV64, DL, MVT::f32, NewOp0);
64246425
}
6425-
if (VT == MVT::f64 && Op0VT == MVT::i64 && XLenVT == MVT::i32) {
6426+
if (VT == MVT::f64 && Op0VT == MVT::i64 && !Subtarget.is64Bit() &&
6427+
Subtarget.hasStdExtDOrZdinx()) {
64266428
SDValue Lo, Hi;
64276429
std::tie(Lo, Hi) = DAG.SplitScalar(Op0, DL, MVT::i32, MVT::i32);
64286430
return DAG.getNode(RISCVISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
@@ -12940,7 +12942,8 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1294012942
SDValue FPConv =
1294112943
DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, MVT::i64, Op0);
1294212944
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, FPConv));
12943-
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && XLenVT == MVT::i32) {
12945+
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && !Subtarget.is64Bit() &&
12946+
Subtarget.hasStdExtDOrZdinx()) {
1294412947
SDValue NewReg = DAG.getNode(RISCVISD::SplitF64, DL,
1294512948
DAG.getVTList(MVT::i32, MVT::i32), Op0);
1294612949
SDValue RetReg = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64,

llvm/lib/Transforms/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_llvm_component_library(LLVMTransformUtils
3737
InstructionNamer.cpp
3838
Instrumentation.cpp
3939
IntegerDivision.cpp
40+
IRNormalizer.cpp
4041
LCSSA.cpp
4142
LibCallsShrinkWrap.cpp
4243
Local.cpp

0 commit comments

Comments
 (0)