Skip to content

Commit

Permalink
Merged main:bca16e2fbb45 into amd-gfx:4bb996d53d7e
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4bb996d Merged main:25c1578a46ff into amd-gfx:237762389aa0
Remote branch main bca16e2 [LTO] Remove options to disable inlining, vectorization & GVNLoadPRE.
  • Loading branch information
Sw authored and Sw committed Jan 16, 2021
2 parents 4bb996d + bca16e2 commit c26ff42
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 67 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Config/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* Indicate that this is LLVM compiled from the amd-gfx branch. */
#define LLVM_HAVE_BRANCH_AMD_GFX
#define LLVM_MAIN_REVISION 377200
#define LLVM_MAIN_REVISION 377205

/* Define if LLVM_ENABLE_DUMP is enabled */
#cmakedefine LLVM_ENABLE_DUMP
Expand Down
11 changes: 3 additions & 8 deletions llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,20 @@ struct LTOCodeGenerator {
/// \note It is up to the linker to remove the intermediate output file. Do
/// not try to remove the object file in LTOCodeGenerator's destructor as we
/// don't who (LTOCodeGenerator or the output file) will last longer.
bool compile_to_file(const char **Name, bool DisableVerify,
bool DisableInline, bool DisableGVNLoadPRE,
bool DisableVectorization);
bool compile_to_file(const char **Name, bool DisableVerify);

/// As with compile_to_file(), this function compiles the merged module into
/// single output file. Instead of returning the output file path to the
/// caller (linker), it brings the output to a buffer, and returns the buffer
/// to the caller. This function should delete the intermediate file once
/// its content is brought to memory. Return NULL if the compilation was not
/// successful.
std::unique_ptr<MemoryBuffer> compile(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization);
std::unique_ptr<MemoryBuffer> compile(bool DisableVerify);

/// Optimizes the merged module. Returns true on success.
///
/// Calls \a verifyMergedModuleOnce().
bool optimize(bool DisableVerify, bool DisableInline, bool DisableGVNLoadPRE,
bool DisableVectorization);
bool optimize(bool DisableVerify);

/// Compiles the merged optimized module into a single output file. It brings
/// the output to a buffer, and returns the buffer to the caller. Return NULL
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,14 @@ static Value *SimplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
match(Op0, m_c_Xor(m_Not(m_Specific(A)), m_Specific(B)))))
return Op0;

// (~A & B) | ~(A | B) --> ~A
// (~A & B) | ~(B | A) --> ~A
// (B & ~A) | ~(A | B) --> ~A
// (B & ~A) | ~(B | A) --> ~A
if (match(Op0, m_And(m_Not(m_Value(A)), m_Value(B))) &&
match(Op1, m_Not(m_c_Or(m_Specific(A), m_Specific(B)))))
return cast<BinaryOperator>(Op0)->getOperand(0);

if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, false))
return V;

Expand Down
27 changes: 8 additions & 19 deletions llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,15 @@ LTOCodeGenerator::compileOptimized() {
return std::move(*BufferOrErr);
}

bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify,
bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization) {
if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableVectorization))
bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify) {
if (!optimize(DisableVerify))
return false;

return compileOptimizedToFile(Name);
}

std::unique_ptr<MemoryBuffer>
LTOCodeGenerator::compile(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE, bool DisableVectorization) {
if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableVectorization))
std::unique_ptr<MemoryBuffer> LTOCodeGenerator::compile(bool DisableVerify) {
if (!optimize(DisableVerify))
return nullptr;

return compileOptimized();
Expand Down Expand Up @@ -534,9 +527,7 @@ void LTOCodeGenerator::finishOptimizationRemarks() {
}

/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization) {
bool LTOCodeGenerator::optimize(bool DisableVerify) {
if (!this->determineTarget())
return false;

Expand Down Expand Up @@ -585,11 +576,9 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,

Triple TargetTriple(TargetMach->getTargetTriple());
PassManagerBuilder PMB;
PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
PMB.LoopVectorize = !DisableVectorization;
PMB.SLPVectorize = !DisableVectorization;
if (!DisableInline)
PMB.Inliner = createFunctionInliningPass();
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
PMB.Inliner = createFunctionInliningPass();
PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
if (Freestanding)
PMB.LibraryInfo->disableAllFunctions();
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/RISCV/RISCVRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,10 @@ let RegAltNameIndices = [ABIRegAltName] in {
class VReg<list<ValueType> regTypes, dag regList, int Vlmul>
: RegisterClass<"RISCV",
regTypes,
// FIXME: Spill alignment set to 16 bytes.
128,
64, // The maximum supported ELEN is 64.
regList> {
int VLMul = Vlmul;
int Size = !mul(Vlmul, 64); // FIXME: assuming ELEN=64
int Size = !mul(Vlmul, 64);
}

def VR : VReg<[vint8mf2_t, vint8mf4_t, vint8mf8_t,
Expand Down
1 change: 0 additions & 1 deletion llvm/test/Transforms/InstCombine/or.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1369,4 +1369,3 @@ define i32 @test5_use3(i32 %x, i32 %y) {
%or1 = or i32 %xor, %neg
ret i32 %or1
}

94 changes: 94 additions & 0 deletions llvm/test/Transforms/InstSimplify/or.ll
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,97 @@ define i32 @poison(i32 %x) {
%v = or i32 %x, poison
ret i32 %v
}

declare void @use(i32)

define i32 @and_or_not_or(i32 %A, i32 %B) {
; CHECK-LABEL: @and_or_not_or(
; CHECK-NEXT: [[I:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: ret i32 [[I]]
;
%i = xor i32 %B, -1
%i2 = and i32 %i, %A
%i3 = or i32 %B, %A
%i4 = xor i32 %i3, -1
%i5 = or i32 %i2, %i4
ret i32 %i5
}

define i32 @and_or_not_or2(i32 %A, i32 %B) {
; CHECK-LABEL: @and_or_not_or2(
; CHECK-NEXT: [[I:%.*]] = xor i32 [[A:%.*]], -1
; CHECK-NEXT: ret i32 [[I]]
;
%i = xor i32 %A, -1
%i2 = and i32 %i, %B
%i3 = or i32 %B, %A
%i4 = xor i32 %i3, -1
%i5 = or i32 %i2, %i4
ret i32 %i5
}

define <4 x i32> @and_or_not_or3_vec(<4 x i32> %A, <4 x i32> %B) {
; CHECK-LABEL: @and_or_not_or3_vec(
; CHECK-NEXT: [[I:%.*]] = xor <4 x i32> [[A:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
; CHECK-NEXT: ret <4 x i32> [[I]]
;
%i = xor <4 x i32> %A, <i32 -1, i32 -1, i32 -1, i32 -1>
%i2 = and <4 x i32> %i, %B
%i3 = or <4 x i32> %B, %A
%i4 = xor <4 x i32> %i3, <i32 -1, i32 -1, i32 -1, i32 -1>
%i5 = or <4 x i32> %i2, %i4
ret <4 x i32> %i5
}

define i32 @and_or_not_or4_use(i32 %A, i32 %B) {
; CHECK-LABEL: @and_or_not_or4_use(
; CHECK-NEXT: [[I:%.*]] = xor i32 [[A:%.*]], -1
; CHECK-NEXT: [[I2:%.*]] = and i32 [[I]], [[B:%.*]]
; CHECK-NEXT: tail call void @use(i32 [[I2]])
; CHECK-NEXT: ret i32 [[I]]
;
%i = xor i32 %A, -1
%i2 = and i32 %i, %B
tail call void @use(i32 %i2)
%i3 = or i32 %B, %A
%i4 = xor i32 %i3, -1
%i5 = or i32 %i2, %i4
ret i32 %i5
}

define i32 @and_or_not_or4_use2(i32 %A, i32 %B) {
; CHECK-LABEL: @and_or_not_or4_use2(
; CHECK-NEXT: [[I:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: [[I2:%.*]] = xor i32 [[I]], -1
; CHECK-NEXT: tail call void @use(i32 [[I2]])
; CHECK-NEXT: [[I3:%.*]] = xor i32 [[A]], -1
; CHECK-NEXT: ret i32 [[I3]]
;
%i = or i32 %B, %A
%i2 = xor i32 %i, -1
tail call void @use(i32 %i2)
%i3 = xor i32 %A, -1
%i4 = and i32 %i3, %B
%i5 = or i32 %i4, %i2
ret i32 %i5
}

define i32 @and_or_not_or4_use3(i32 %A, i32 %B) {
; CHECK-LABEL: @and_or_not_or4_use3(
; CHECK-NEXT: [[I:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: [[I2:%.*]] = xor i32 [[I]], -1
; CHECK-NEXT: tail call void @use(i32 [[I2]])
; CHECK-NEXT: [[I3:%.*]] = xor i32 [[A]], -1
; CHECK-NEXT: [[I4:%.*]] = and i32 [[I3]], [[B]]
; CHECK-NEXT: tail call void @use(i32 [[I4]])
; CHECK-NEXT: ret i32 [[I3]]
;
%i = or i32 %B, %A
%i2 = xor i32 %i, -1
tail call void @use(i32 %i2)
%i3 = xor i32 %A, -1
%i4 = and i32 %i3, %B
tail call void @use(i32 %i4)
%i5 = or i32 %i4, %i2
ret i32 %i5
}
17 changes: 2 additions & 15 deletions llvm/tools/llvm-lto/llvm-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ static cl::opt<bool> DisableVerify(
"disable-verify", cl::init(false),
cl::desc("Do not run the verifier during the optimization pipeline"));

static cl::opt<bool> DisableInline("disable-inlining", cl::init(false),
cl::desc("Do not run the inliner pass"));

static cl::opt<bool>
DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
cl::desc("Do not run the GVN load PRE pass"));

static cl::opt<bool> DisableLTOVectorization(
"disable-lto-vectorization", cl::init(false),
cl::desc("Do not run loop or slp vectorization during LTO"));

static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
Expand Down Expand Up @@ -1042,8 +1031,7 @@ int main(int argc, char **argv) {
error("writing linked module failed.");
}

if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization)) {
if (!CodeGen.optimize(DisableVerify)) {
// Diagnostic messages should have been printed by the handler.
error("error optimizing the code");
}
Expand Down Expand Up @@ -1084,8 +1072,7 @@ int main(int argc, char **argv) {
error(": -save-merged-module must be specified with -o");

const char *OutputName = nullptr;
if (!CodeGen.compile_to_file(&OutputName, DisableVerify, DisableInline,
DisableGVNLoadPRE, DisableLTOVectorization))
if (!CodeGen.compile_to_file(&OutputName, DisableVerify))
error("error compiling the code");
// Diagnostic messages should have been printed by the handler.

Expand Down
23 changes: 3 additions & 20 deletions llvm/tools/lto/lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ OptLevel("O",
cl::ZeroOrMore,
cl::init('2'));

static cl::opt<bool>
DisableInline("disable-inlining", cl::init(false),
cl::desc("Do not run the inliner pass"));

static cl::opt<bool>
DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
cl::desc("Do not run the GVN load PRE pass"));

static cl::opt<bool> DisableLTOVectorization(
"disable-lto-vectorization", cl::init(false),
cl::desc("Do not run loop or slp vectorization during LTO"));

static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
Expand Down Expand Up @@ -448,9 +436,7 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
maybeParseOptions(cg);
LibLTOCodeGenerator *CG = unwrap(cg);
CG->NativeObjectFile =
CG->compile(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
CG->NativeObjectFile = CG->compile(DisableVerify);
if (!CG->NativeObjectFile)
return nullptr;
*length = CG->NativeObjectFile->getBufferSize();
Expand All @@ -459,8 +445,7 @@ const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {

bool lto_codegen_optimize(lto_code_gen_t cg) {
maybeParseOptions(cg);
return !unwrap(cg)->optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
return !unwrap(cg)->optimize(DisableVerify);
}

const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
Expand All @@ -475,9 +460,7 @@ const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {

bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
maybeParseOptions(cg);
return !unwrap(cg)->compile_to_file(
name, DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
return !unwrap(cg)->compile_to_file(name, DisableVerify);
}

void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {
Expand Down

0 comments on commit c26ff42

Please sign in to comment.