Index: lib/Target/RISCV/RISCVISelLowering.cpp =================================================================== --- lib/Target/RISCV/RISCVISelLowering.cpp +++ lib/Target/RISCV/RISCVISelLowering.cpp @@ -142,8 +142,9 @@ setBooleanContents(ZeroOrOneBooleanContent); // Function alignments (log2). - setMinFunctionAlignment(3); - setPrefFunctionAlignment(3); + unsigned FunctionAlignment = Subtarget.hasStdExtC() ? 1 : 2; + setMinFunctionAlignment(FunctionAlignment); + setPrefFunctionAlignment(FunctionAlignment); // Effectively disable jump table generation. setMinimumJumpTableEntries(INT_MAX); Index: test/CodeGen/RISCV/align.ll =================================================================== --- /dev/null +++ test/CodeGen/RISCV/align.ll @@ -0,0 +1,13 @@ +; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \ +; RUN: | FileCheck %s -check-prefix=RV32I +; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \ +; RUN: | FileCheck %s -check-prefix=RV32C + +define void @foo() { +;RV32I: .p2align 2 +;RV32I: foo: +;RV32C: .p2align 1 +;RV32C: foo: +entry: + ret void +}