Skip to content

Commit 8233a04

Browse files
committed
improve the code and update some tests
1 parent 9628b7d commit 8233a04

File tree

5 files changed

+405
-996
lines changed

5 files changed

+405
-996
lines changed

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
205205
// TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
206206
// arch feature set will be used to include all sub-features belonging to
207207
// the V1.1 ISA version.
208-
if (HasFeatureFrecipe || HasFeatureLAM_BH)
208+
if (HasFeatureFrecipe && HasFeatureLAM_BH)
209209
Builder.defineMacro("__loongarch_arch",
210210
Twine('"') + "la64v1.1" + Twine('"'));
211211
else

clang/test/Preprocessor/init-loongarch.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,29 +819,29 @@
819819
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang -lsx | \
820820
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s
821821
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +frecipe | \
822-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s
822+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
823823
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx | \
824824
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
825825
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 | \
826826
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la64v1.1 -DTUNE=loongarch64 %s
827827
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -frecipe | \
828-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.1 -DTUNE=loongarch64 %s
828+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
829829
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -lsx | \
830830
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=loongarch64 -DTUNE=loongarch64 %s
831831
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +frecipe | \
832832
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s
833833
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +frecipe | \
834-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s
834+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
835835
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +lam-bh | \
836-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.1 -DTUNE=loongarch64 %s
836+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
837837
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -lam-bh | \
838-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s
838+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
839839
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lam-bh | \
840840
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=loongarch64 -DTUNE=loongarch64 %s
841841
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +lam-bh | \
842-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.1 -DTUNE=loongarch64 %s
843-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -frecipe -Xclang -target-feature -Xclang -lam-bh | \
844-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
842+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
843+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +frecipe -Xclang -target-feature -Xclang +lam-bh | \
844+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE -DARCH=la64v1.1 -DTUNE=loongarch64 %s
845845
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \
846846
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la664 -DTUNE=la664 %s
847847
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5737,7 +5737,8 @@ LoongArchTargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const {
57375737

57385738
if (Subtarget.hasLAM_BH() && Subtarget.is64Bit() &&
57395739
(AI->getOperation() == AtomicRMWInst::Xchg ||
5740-
AI->getOperation() == AtomicRMWInst::Add)) {
5740+
AI->getOperation() == AtomicRMWInst::Add ||
5741+
AI->getOperation() == AtomicRMWInst::Sub)) {
57415742
return AtomicExpansionKind::None;
57425743
}
57435744

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,12 +2101,23 @@ multiclass binary_atomic_op_bh<string inst, string op> {
21012101
(!cast<Instruction>(inst#"__DB_H") GPR:$rk, GPR:$rj)>;
21022102
}
21032103

2104-
let Predicates = [IsLA64] in {
2105-
2106-
let Predicates = [ HasLAM_BH ] in {
2104+
let Predicates = [ HasLAM_BH, IsLA64 ] in {
2105+
21072106
defm : binary_atomic_op_bh<"AMSWAP", "atomic_swap">;
21082107
defm : binary_atomic_op_bh<"AMADD", "atomic_load_add">;
2109-
}
2108+
def : Pat<(atomic_load_sub_i8_monotonic GPR:$rj, GPR:$rk),
2109+
(AMADD_B (SUB_W R0, GPR:$rk), GPR:$rj)>;
2110+
def : Pat<(atomic_load_sub_i16_monotonic GPR:$rj, GPR:$rk),
2111+
(AMADD_H (SUB_W R0, GPR:$rk), GPR:$rj)>;
2112+
2113+
def : Pat<(atomic_load_sub_i8 GPR:$rj, GPR:$rk),
2114+
(AMADD__DB_B (SUB_W R0, GPR:$rk), GPR:$rj)>;
2115+
def : Pat<(atomic_load_sub_i16 GPR:$rj, GPR:$rk),
2116+
(AMADD__DB_H (SUB_W R0, GPR:$rk), GPR:$rj)>;
2117+
} // Predicates = [ IsLA64, HasLAM_BH ]
2118+
2119+
2120+
let Predicates = [IsLA64] in {
21102121

21112122
defm : binary_atomic_op_wd<"AMSWAP", "atomic_swap">;
21122123
defm : binary_atomic_op_wd<"AMADD", "atomic_load_add">;

0 commit comments

Comments
 (0)