[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)

2025-06-15 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/143295


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)

2025-06-15 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/143295


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Backport 90a52f494296 to release/20.x (PR #144299)

2025-06-15 Thread via llvm-branch-commits

https://github.com/leecheechen created 
https://github.com/llvm/llvm-project/pull/144299

This patch will fix #143239

>From c9f683ae8aba35c28a9125629f737a20ece262ce Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Sat, 7 Jun 2025 15:10:24 +0800
Subject: [PATCH 1/2] [LoongArch] Precommit test case to show bug in
 LoongArchISelDagToDag

The optimization level should not be restored into O2.

(cherry picked from commit fcc82cfa9394b2bd4380acdcf0e2854caee5a47a)
---
 llvm/test/CodeGen/LoongArch/isel-optnone.ll | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 llvm/test/CodeGen/LoongArch/isel-optnone.ll

diff --git a/llvm/test/CodeGen/LoongArch/isel-optnone.ll 
b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
new file mode 100644
index 0..d44f1405d0c18
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
@@ -0,0 +1,13 @@
+; REQUIRES: asserts
+; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | 
FileCheck %s
+
+define void @fooOptnone() #0 {
+; CHECK: Changing optimization level for Function fooOptnone
+; CHECK: Before: -O2 ; After: -O0
+
+; CHECK: Restoring optimization level for Function fooOptnone
+; CHECK: Before: -O0 ; After: -O2
+  ret void
+}
+
+attributes #0 = { nounwind optnone noinline }

>From 0bd6913dfde8d429c5dd93d8ffbbf52485463357 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Sat, 7 Jun 2025 11:45:39 +0800
Subject: [PATCH 2/2] [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel
 correctly

Like many other targets did. And see RISCV for similar fix.

Fix https://github.com/llvm/llvm-project/issues/143239

(cherry picked from commit 90a52f4942961a5c32afc69d69470c6b7e5bcb8a)
---
 llvm/lib/Target/LoongArch/LoongArch.h|  3 ++-
 llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp  | 10 ++
 llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h|  8 +---
 llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp |  2 +-
 llvm/test/CodeGen/LoongArch/O0-pipeline.ll   |  8 
 llvm/test/CodeGen/LoongArch/isel-optnone.ll  |  7 ++-
 llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll |  1 +
 7 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArch.h 
b/llvm/lib/Target/LoongArch/LoongArch.h
index db60523738880..6635c57ff0476 100644
--- a/llvm/lib/Target/LoongArch/LoongArch.h
+++ b/llvm/lib/Target/LoongArch/LoongArch.h
@@ -35,7 +35,8 @@ bool lowerLoongArchMachineOperandToMCOperand(const 
MachineOperand &MO,
 
 FunctionPass *createLoongArchDeadRegisterDefinitionsPass();
 FunctionPass *createLoongArchExpandAtomicPseudoPass();
-FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM);
+FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM,
+ CodeGenOptLevel OptLevel);
 FunctionPass *createLoongArchMergeBaseOffsetOptPass();
 FunctionPass *createLoongArchOptWInstrsPass();
 FunctionPass *createLoongArchPreRAExpandPseudoPass();
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
index cb0fb9bc9c7f9..7169cdc9a2bf9 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
@@ -25,8 +25,9 @@ using namespace llvm;
 char LoongArchDAGToDAGISelLegacy::ID;
 
 LoongArchDAGToDAGISelLegacy::LoongArchDAGToDAGISelLegacy(
-LoongArchTargetMachine &TM)
-: SelectionDAGISelLegacy(ID, std::make_unique(TM)) 
{}
+LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
+: SelectionDAGISelLegacy(
+  ID, std::make_unique(TM, OptLevel)) {}
 
 INITIALIZE_PASS(LoongArchDAGToDAGISelLegacy, DEBUG_TYPE, PASS_NAME, false,
 false)
@@ -456,6 +457,7 @@ bool LoongArchDAGToDAGISel::selectVSplatUimmPow2(SDValue N,
 
 // This pass converts a legalized DAG into a LoongArch-specific DAG, ready
 // for instruction scheduling.
-FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM) {
-  return new LoongArchDAGToDAGISelLegacy(TM);
+FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM,
+   CodeGenOptLevel OptLevel) {
+  return new LoongArchDAGToDAGISelLegacy(TM, OptLevel);
 }
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h 
b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
index 8a7eba418d804..2e6bc9951e9e7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
@@ -26,8 +26,9 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
 public:
   LoongArchDAGToDAGISel() = delete;
 
-  explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM)
-  : SelectionDAGISel(TM) {}
+  explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM,
+ CodeGenOptLevel OptLevel)
+  : SelectionDAGISel(TM, OptLevel) {}
 
   bool runOnMachineFunction(MachineFunction &MF) override {
 Subtarget = &MF.getSubtarget()

[llvm-branch-commits] [llvm] Backport 90a52f494296 to release/20.x (PR #144299)

2025-06-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (leecheechen)


Changes

This patch will fix #143239

---
Full diff: https://github.com/llvm/llvm-project/pull/144299.diff


7 Files Affected:

- (modified) llvm/lib/Target/LoongArch/LoongArch.h (+2-1) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp (+6-4) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h (+5-3) 
- (modified) llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp (+1-1) 
- (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-8) 
- (added) llvm/test/CodeGen/LoongArch/isel-optnone.ll (+10) 
- (modified) llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll (+1) 


``diff
diff --git a/llvm/lib/Target/LoongArch/LoongArch.h 
b/llvm/lib/Target/LoongArch/LoongArch.h
index db60523738880..6635c57ff0476 100644
--- a/llvm/lib/Target/LoongArch/LoongArch.h
+++ b/llvm/lib/Target/LoongArch/LoongArch.h
@@ -35,7 +35,8 @@ bool lowerLoongArchMachineOperandToMCOperand(const 
MachineOperand &MO,
 
 FunctionPass *createLoongArchDeadRegisterDefinitionsPass();
 FunctionPass *createLoongArchExpandAtomicPseudoPass();
-FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM);
+FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM,
+ CodeGenOptLevel OptLevel);
 FunctionPass *createLoongArchMergeBaseOffsetOptPass();
 FunctionPass *createLoongArchOptWInstrsPass();
 FunctionPass *createLoongArchPreRAExpandPseudoPass();
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
index cb0fb9bc9c7f9..7169cdc9a2bf9 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
@@ -25,8 +25,9 @@ using namespace llvm;
 char LoongArchDAGToDAGISelLegacy::ID;
 
 LoongArchDAGToDAGISelLegacy::LoongArchDAGToDAGISelLegacy(
-LoongArchTargetMachine &TM)
-: SelectionDAGISelLegacy(ID, std::make_unique(TM)) 
{}
+LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
+: SelectionDAGISelLegacy(
+  ID, std::make_unique(TM, OptLevel)) {}
 
 INITIALIZE_PASS(LoongArchDAGToDAGISelLegacy, DEBUG_TYPE, PASS_NAME, false,
 false)
@@ -456,6 +457,7 @@ bool LoongArchDAGToDAGISel::selectVSplatUimmPow2(SDValue N,
 
 // This pass converts a legalized DAG into a LoongArch-specific DAG, ready
 // for instruction scheduling.
-FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM) {
-  return new LoongArchDAGToDAGISelLegacy(TM);
+FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM,
+   CodeGenOptLevel OptLevel) {
+  return new LoongArchDAGToDAGISelLegacy(TM, OptLevel);
 }
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h 
b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
index 8a7eba418d804..2e6bc9951e9e7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
@@ -26,8 +26,9 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
 public:
   LoongArchDAGToDAGISel() = delete;
 
-  explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM)
-  : SelectionDAGISel(TM) {}
+  explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM,
+ CodeGenOptLevel OptLevel)
+  : SelectionDAGISel(TM, OptLevel) {}
 
   bool runOnMachineFunction(MachineFunction &MF) override {
 Subtarget = &MF.getSubtarget();
@@ -71,7 +72,8 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
 class LoongArchDAGToDAGISelLegacy : public SelectionDAGISelLegacy {
 public:
   static char ID;
-  explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM);
+  explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM,
+   CodeGenOptLevel OptLevel);
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp 
b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
index 62b08be5435cd..27f97b2cebb0c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
@@ -188,7 +188,7 @@ void LoongArchPassConfig::addCodeGenPrepare() {
 }
 
 bool LoongArchPassConfig::addInstSelector() {
-  addPass(createLoongArchISelDag(getLoongArchTargetMachine()));
+  addPass(createLoongArchISelDag(getLoongArchTargetMachine(), getOptLevel()));
 
   return false;
 }
diff --git a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll 
b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
index 24bd4c75a9821..73d0bda895de0 100644
--- a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
+++ b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
@@ -34,15 +34,7 @@
 ; CHECK-NEXT:   Safe Stack instrumentation pass
 ; CHECK-NEXT:   Insert stack protectors
 ; CHECK-NEXT:   Module Verifier
-; CHECK-NEXT:   Dominator Tree Construction
-; CHECK-NEXT:   Basic Alias Analysis (stateless AA impl)
-; 

[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Precommit test case to show bug in LoongArchISelDagToDag (PR #144296)

2025-06-15 Thread via llvm-branch-commits

leecheechen wrote:

Close as it is redundant after #144299 has been created.

https://github.com/llvm/llvm-project/pull/144296
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)

2025-06-15 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited 
https://github.com/llvm/llvm-project/pull/143296
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)

2025-06-15 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/143296


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)

2025-06-15 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/143296


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Precommit test case to show bug in LoongArchISelDagToDag (PR #144296)

2025-06-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (llvmbot)


Changes

Backport fcc82cf

Requested by: @leecheechen

---
Full diff: https://github.com/llvm/llvm-project/pull/144296.diff


1 Files Affected:

- (added) llvm/test/CodeGen/LoongArch/isel-optnone.ll (+13) 


``diff
diff --git a/llvm/test/CodeGen/LoongArch/isel-optnone.ll 
b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
new file mode 100644
index 0..d44f1405d0c18
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
@@ -0,0 +1,13 @@
+; REQUIRES: asserts
+; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | 
FileCheck %s
+
+define void @fooOptnone() #0 {
+; CHECK: Changing optimization level for Function fooOptnone
+; CHECK: Before: -O2 ; After: -O0
+
+; CHECK: Restoring optimization level for Function fooOptnone
+; CHECK: Before: -O0 ; After: -O2
+  ret void
+}
+
+attributes #0 = { nounwind optnone noinline }

``




https://github.com/llvm/llvm-project/pull/144296
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Precommit test case to show bug in LoongArchISelDagToDag (PR #144296)

2025-06-15 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/144296
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [RISCV] Support non-power-of-2 types when expanding memcmp (PR #114971)

2025-06-15 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/114971

>From 3fd27bd1405a8b2c068786a200d610b9cacb65ef Mon Sep 17 00:00:00 2001
From: Wang Pengcheng 
Date: Tue, 5 Nov 2024 20:38:44 +0800
Subject: [PATCH 1/3] Set max bytes

Created using spr 1.3.6-beta.1
---
 llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp 
b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index c65feb9755633..a1c5f76bae009 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -2508,7 +2508,10 @@ RISCVTTIImpl::enableMemCmpExpansion(bool OptSize, bool 
IsZeroCmp) const {
 Options.LoadSizes = {4, 2, 1};
   if (IsZeroCmp && ST->hasVInstructions()) {
 unsigned VLenB = ST->getRealMinVLen() / 8;
-for (unsigned Size = ST->getXLen() / 8 + 1;
+// The minimum size should be the maximum bytes between `VLen * LMUL_MF8`
+// and `XLen + 8`.
+unsigned MinSize = std::max(VLenB / 8, ST->getXLen() / 8 + 1);
+for (unsigned Size = MinSize;
  Size <= VLenB * ST->getMaxLMULForFixedLengthVectors(); Size++)
   Options.LoadSizes.insert(Options.LoadSizes.begin(), Size);
   }

>From 17115212f1d7af68f5374896d1ddadf464b2bc11 Mon Sep 17 00:00:00 2001
From: Wang Pengcheng 
Date: Fri, 13 Jun 2025 18:24:15 +0800
Subject: [PATCH 2/3] Change to XLen + 1

Created using spr 1.3.6-beta.1
---
 .../Target/RISCV/RISCVTargetTransformInfo.cpp |   4 +-
 llvm/test/CodeGen/RISCV/memcmp-optsize.ll | 324 +++---
 llvm/test/CodeGen/RISCV/memcmp.ll | 324 +++---
 3 files changed, 570 insertions(+), 82 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp 
b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 4b9ea30a92c99..3aa0fcbb723a1 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -2956,8 +2956,8 @@ RISCVTTIImpl::enableMemCmpExpansion(bool OptSize, bool 
IsZeroCmp) const {
   if (IsZeroCmp && ST->hasVInstructions()) {
 unsigned VLenB = ST->getRealMinVLen() / 8;
 // The minimum size should be the maximum bytes between `VLen * LMUL_MF8`
-// and `XLen * 2`.
-unsigned MinSize = std::max(VLenB / 8, ST->getXLen() * 2 / 8);
+// and `XLen + 1`.
+unsigned MinSize = std::max(VLenB / 8, ST->getXLen() / 8 + 1);
 for (unsigned Size = MinSize;
  Size <= VLenB * ST->getMaxLMULForFixedLengthVectors(); Size++)
   Options.LoadSizes.insert(Options.LoadSizes.begin(), Size);
diff --git a/llvm/test/CodeGen/RISCV/memcmp-optsize.ll 
b/llvm/test/CodeGen/RISCV/memcmp-optsize.ll
index d4d12a932d0ec..0d57e4201512e 100644
--- a/llvm/test/CodeGen/RISCV/memcmp-optsize.ll
+++ b/llvm/test/CodeGen/RISCV/memcmp-optsize.ll
@@ -517,17 +517,99 @@ define i32 @bcmp_size_5(ptr %s1, ptr %s2) nounwind 
optsize {
 ; CHECK-ALIGNED-RV64-V-NEXT:addi sp, sp, 16
 ; CHECK-ALIGNED-RV64-V-NEXT:ret
 ;
-; CHECK-UNALIGNED-LABEL: bcmp_size_5:
-; CHECK-UNALIGNED:   # %bb.0: # %entry
-; CHECK-UNALIGNED-NEXT:lw a2, 0(a0)
-; CHECK-UNALIGNED-NEXT:lbu a0, 4(a0)
-; CHECK-UNALIGNED-NEXT:lw a3, 0(a1)
-; CHECK-UNALIGNED-NEXT:lbu a1, 4(a1)
-; CHECK-UNALIGNED-NEXT:xor a2, a2, a3
-; CHECK-UNALIGNED-NEXT:xor a0, a0, a1
-; CHECK-UNALIGNED-NEXT:or a0, a2, a0
-; CHECK-UNALIGNED-NEXT:snez a0, a0
-; CHECK-UNALIGNED-NEXT:ret
+; CHECK-UNALIGNED-RV32-LABEL: bcmp_size_5:
+; CHECK-UNALIGNED-RV32:   # %bb.0: # %entry
+; CHECK-UNALIGNED-RV32-NEXT:lw a2, 0(a0)
+; CHECK-UNALIGNED-RV32-NEXT:lbu a0, 4(a0)
+; CHECK-UNALIGNED-RV32-NEXT:lw a3, 0(a1)
+; CHECK-UNALIGNED-RV32-NEXT:lbu a1, 4(a1)
+; CHECK-UNALIGNED-RV32-NEXT:xor a2, a2, a3
+; CHECK-UNALIGNED-RV32-NEXT:xor a0, a0, a1
+; CHECK-UNALIGNED-RV32-NEXT:or a0, a2, a0
+; CHECK-UNALIGNED-RV32-NEXT:snez a0, a0
+; CHECK-UNALIGNED-RV32-NEXT:ret
+;
+; CHECK-UNALIGNED-RV64-LABEL: bcmp_size_5:
+; CHECK-UNALIGNED-RV64:   # %bb.0: # %entry
+; CHECK-UNALIGNED-RV64-NEXT:lw a2, 0(a0)
+; CHECK-UNALIGNED-RV64-NEXT:lbu a0, 4(a0)
+; CHECK-UNALIGNED-RV64-NEXT:lw a3, 0(a1)
+; CHECK-UNALIGNED-RV64-NEXT:lbu a1, 4(a1)
+; CHECK-UNALIGNED-RV64-NEXT:xor a2, a2, a3
+; CHECK-UNALIGNED-RV64-NEXT:xor a0, a0, a1
+; CHECK-UNALIGNED-RV64-NEXT:or a0, a2, a0
+; CHECK-UNALIGNED-RV64-NEXT:snez a0, a0
+; CHECK-UNALIGNED-RV64-NEXT:ret
+;
+; CHECK-UNALIGNED-RV32-ZBB-LABEL: bcmp_size_5:
+; CHECK-UNALIGNED-RV32-ZBB:   # %bb.0: # %entry
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:lw a2, 0(a0)
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:lbu a0, 4(a0)
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:lw a3, 0(a1)
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:lbu a1, 4(a1)
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:xor a2, a2, a3
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:xor a0, a0, a1
+; CHECK-UNALIGNED-RV32-ZBB-NEXT:or a0, a2, a0

[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Precommit test case to show bug in LoongArchISelDagToDag (PR #144296)

2025-06-15 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/144296

Backport fcc82cf

Requested by: @leecheechen

>From 82272742df0b664c54e07b1f45634e07933dbfd4 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Sat, 7 Jun 2025 15:10:24 +0800
Subject: [PATCH] [LoongArch] Precommit test case to show bug in
 LoongArchISelDagToDag

The optimization level should not be restored into O2.

(cherry picked from commit fcc82cfa9394b2bd4380acdcf0e2854caee5a47a)
---
 llvm/test/CodeGen/LoongArch/isel-optnone.ll | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 llvm/test/CodeGen/LoongArch/isel-optnone.ll

diff --git a/llvm/test/CodeGen/LoongArch/isel-optnone.ll 
b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
new file mode 100644
index 0..d44f1405d0c18
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
@@ -0,0 +1,13 @@
+; REQUIRES: asserts
+; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | 
FileCheck %s
+
+define void @fooOptnone() #0 {
+; CHECK: Changing optimization level for Function fooOptnone
+; CHECK: Before: -O2 ; After: -O0
+
+; CHECK: Restoring optimization level for Function fooOptnone
+; CHECK: Before: -O0 ; After: -O2
+  ret void
+}
+
+attributes #0 = { nounwind optnone noinline }

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

AmrDeveloper wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/144262?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#144262** https://app.graphite.dev/github/pr/llvm/llvm-project/144262?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/144262?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#144261** https://app.graphite.dev/github/pr/llvm/llvm-project/144261?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#144236** https://app.graphite.dev/github/pr/llvm/llvm-project/144236?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#144235** https://app.graphite.dev/github/pr/llvm/llvm-project/144235?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/144262
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/144261

None

>From 9cbbfd20f045ca71e51d5bddd5e2bbe5a8ddd22f Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 15 Jun 2025 14:44:11 +0200
Subject: [PATCH] [CIR] Upstream __real__ for ComplexType

---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 21 
 clang/test/CIR/CodeGen/complex.cpp | 23 ++
 2 files changed, 44 insertions(+)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 75b4d2a637e6e..615a0e7bef556 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -603,6 +603,8 @@ class ScalarExprEmitter : public 
StmtVisitor {
 
   mlir::Value VisitUnaryLNot(const UnaryOperator *e);
 
+  mlir::Value VisitUnaryReal(const UnaryOperator *e);
+
   mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); }
 
   /// Emit a conversion from the specified type to the specified destination
@@ -1891,6 +1893,25 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const 
UnaryOperator *e) {
   return maybePromoteBoolResult(boolVal, cgf.convertType(e->getType()));
 }
 
+mlir::Value ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *e) {
+  // TODO(cir): handle scalar promotion.
+  Expr *op = e->getSubExpr();
+  if (op->getType()->isAnyComplexType()) {
+// If it's an l-value, load through the appropriate subobject l-value.
+// Note that we have to ask E because Op might be an l-value that
+// this won't work for, e.g. an Obj-C property.
+if (e->isGLValue())
+  return cgf.emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc())
+  .getScalarVal();
+
+// Otherwise, calculate and project.
+cgf.cgm.errorNYI(e->getSourceRange(),
+ "VisitUnaryReal calculate and project");
+  }
+
+  return Visit(op);
+}
+
 /// Return the size or alignment of the type of argument of the sizeof
 /// expression as an integer.
 mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 4bccf65cceb13..3d1e395d7613c 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -203,3 +203,26 @@ void foo11() {
 
 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
 // OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+
+void foo12() {
+  double _Complex c;
+  double real = __real__ c;
+}
+
+// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c"]
+// CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr, ["real", 
init]
+// CIR: %[[REAL_PTR:.*]] = cir.complex.real_ptr %[[COMPLEX]] : 
!cir.ptr> -> !cir.ptr
+// CIR: %[[REAL:.*]] = cir.load{{.*}} %[[REAL_PTR]] : !cir.ptr, 
!cir.double
+// CIR: cir.store{{.*}} %[[REAL]], %[[INIT]] : !cir.double, 
!cir.ptr
+
+// LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
+// LLVM: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// LLVM: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// LLVM: store double %[[REAL]], ptr %[[INIT]], align 8
+
+// OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT:.*]] = alloca double, align 8
+// OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// OGCG: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// OGCG: store double %[[REAL]], ptr %[[INIT]], align 8

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/144262

None

>From fa6756886c5e0d432445d2364d92ff38ad0127ae Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 15 Jun 2025 14:45:12 +0200
Subject: [PATCH] [CIR] Upstream __imag__ for ComplexType

---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 20 +++
 clang/test/CIR/CodeGen/complex.cpp | 23 ++
 2 files changed, 43 insertions(+)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 615a0e7bef556..a1896c5e7f7e5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -604,6 +604,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value VisitUnaryLNot(const UnaryOperator *e);
 
   mlir::Value VisitUnaryReal(const UnaryOperator *e);
+  mlir::Value VisitUnaryImag(const UnaryOperator *e);
 
   mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); }
 
@@ -1912,6 +1913,25 @@ mlir::Value ScalarExprEmitter::VisitUnaryReal(const 
UnaryOperator *e) {
   return Visit(op);
 }
 
+mlir::Value ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *e) {
+  // TODO(cir): handle scalar promotion.
+  Expr *op = e->getSubExpr();
+  if (op->getType()->isAnyComplexType()) {
+// If it's an l-value, load through the appropriate subobject l-value.
+// Note that we have to ask E because Op might be an l-value that
+// this won't work for, e.g. an Obj-C property.
+if (e->isGLValue())
+  return cgf.emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc())
+  .getScalarVal();
+
+// Otherwise, calculate and project.
+cgf.cgm.errorNYI(e->getSourceRange(),
+ "VisitUnaryImag calculate and project");
+  }
+
+  return Visit(op);
+}
+
 /// Return the size or alignment of the type of argument of the sizeof
 /// expression as an integer.
 mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 3d1e395d7613c..6c29dc3e1b7fe 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -226,3 +226,26 @@ void foo12() {
 // OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
 // OGCG: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
 // OGCG: store double %[[REAL]], ptr %[[INIT]], align 8
+
+void foo13() {
+  double _Complex c;
+  double imag = __imag__ c;
+}
+
+// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c"]
+// CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr, ["imag", 
init]
+// CIR: %[[IMAG_PTR:.*]] = cir.complex.imag_ptr %[[COMPLEX]] : 
!cir.ptr> -> !cir.ptr
+// CIR: %[[IMAG:.*]] = cir.load{{.*}} %[[REAL_PTR]] : !cir.ptr, 
!cir.double
+// CIR: cir.store{{.*}} %[[IMAG]], %[[INIT]] : !cir.double, 
!cir.ptr
+
+// LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
+// LLVM: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+// LLVM: %[[IMAG:.*]] = load double, ptr %[[IMAG_PTR]], align 8
+// LLVM: store double %[[IMAG]], ptr %[[INIT]], align 8
+
+// OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT:.*]] = alloca double, align 8
+// OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+// OGCG: %[[IMAG:.*]] = load double, ptr %[[IMAG_PTR]], align 8
+// OGCG: store double %[[IMAG]], ptr %[[INIT]], align 8

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

AmrDeveloper wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/144261?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#144262** https://app.graphite.dev/github/pr/llvm/llvm-project/144262?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#144261** https://app.graphite.dev/github/pr/llvm/llvm-project/144261?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/144261?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#144236** https://app.graphite.dev/github/pr/llvm/llvm-project/144236?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#144235** https://app.graphite.dev/github/pr/llvm/llvm-project/144235?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/144261
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper edited 
https://github.com/llvm/llvm-project/pull/144262
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper edited 
https://github.com/llvm/llvm-project/pull/144261
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper ready_for_review 
https://github.com/llvm/llvm-project/pull/144262
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper ready_for_review 
https://github.com/llvm/llvm-project/pull/144261
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread Amr Hesham via llvm-branch-commits

https://github.com/AmrDeveloper edited 
https://github.com/llvm/llvm-project/pull/144262
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __imag__ for ComplexType (PR #144262)

2025-06-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for `__imag__` for ComplexType

https://github.com/llvm/llvm-project/issues/141365

---
Full diff: https://github.com/llvm/llvm-project/pull/144262.diff


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+20) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+23) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 615a0e7bef556..a1896c5e7f7e5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -604,6 +604,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value VisitUnaryLNot(const UnaryOperator *e);
 
   mlir::Value VisitUnaryReal(const UnaryOperator *e);
+  mlir::Value VisitUnaryImag(const UnaryOperator *e);
 
   mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); }
 
@@ -1912,6 +1913,25 @@ mlir::Value ScalarExprEmitter::VisitUnaryReal(const 
UnaryOperator *e) {
   return Visit(op);
 }
 
+mlir::Value ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *e) {
+  // TODO(cir): handle scalar promotion.
+  Expr *op = e->getSubExpr();
+  if (op->getType()->isAnyComplexType()) {
+// If it's an l-value, load through the appropriate subobject l-value.
+// Note that we have to ask E because Op might be an l-value that
+// this won't work for, e.g. an Obj-C property.
+if (e->isGLValue())
+  return cgf.emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc())
+  .getScalarVal();
+
+// Otherwise, calculate and project.
+cgf.cgm.errorNYI(e->getSourceRange(),
+ "VisitUnaryImag calculate and project");
+  }
+
+  return Visit(op);
+}
+
 /// Return the size or alignment of the type of argument of the sizeof
 /// expression as an integer.
 mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 3d1e395d7613c..6c29dc3e1b7fe 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -226,3 +226,26 @@ void foo12() {
 // OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
 // OGCG: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
 // OGCG: store double %[[REAL]], ptr %[[INIT]], align 8
+
+void foo13() {
+  double _Complex c;
+  double imag = __imag__ c;
+}
+
+// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c"]
+// CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr, ["imag", 
init]
+// CIR: %[[IMAG_PTR:.*]] = cir.complex.imag_ptr %[[COMPLEX]] : 
!cir.ptr> -> !cir.ptr
+// CIR: %[[IMAG:.*]] = cir.load{{.*}} %[[REAL_PTR]] : !cir.ptr, 
!cir.double
+// CIR: cir.store{{.*}} %[[IMAG]], %[[INIT]] : !cir.double, 
!cir.ptr
+
+// LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
+// LLVM: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+// LLVM: %[[IMAG:.*]] = load double, ptr %[[IMAG_PTR]], align 8
+// LLVM: store double %[[IMAG]], ptr %[[INIT]], align 8
+
+// OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT:.*]] = alloca double, align 8
+// OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+// OGCG: %[[IMAG:.*]] = load double, ptr %[[IMAG_PTR]], align 8
+// OGCG: store double %[[IMAG]], ptr %[[INIT]], align 8

``




https://github.com/llvm/llvm-project/pull/144262
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for __real__ for ComplexType

https://github.com/llvm/llvm-project/issues/141365

---
Full diff: https://github.com/llvm/llvm-project/pull/144261.diff


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+21) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+23) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 75b4d2a637e6e..615a0e7bef556 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -603,6 +603,8 @@ class ScalarExprEmitter : public 
StmtVisitor {
 
   mlir::Value VisitUnaryLNot(const UnaryOperator *e);
 
+  mlir::Value VisitUnaryReal(const UnaryOperator *e);
+
   mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); }
 
   /// Emit a conversion from the specified type to the specified destination
@@ -1891,6 +1893,25 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const 
UnaryOperator *e) {
   return maybePromoteBoolResult(boolVal, cgf.convertType(e->getType()));
 }
 
+mlir::Value ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *e) {
+  // TODO(cir): handle scalar promotion.
+  Expr *op = e->getSubExpr();
+  if (op->getType()->isAnyComplexType()) {
+// If it's an l-value, load through the appropriate subobject l-value.
+// Note that we have to ask E because Op might be an l-value that
+// this won't work for, e.g. an Obj-C property.
+if (e->isGLValue())
+  return cgf.emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc())
+  .getScalarVal();
+
+// Otherwise, calculate and project.
+cgf.cgm.errorNYI(e->getSourceRange(),
+ "VisitUnaryReal calculate and project");
+  }
+
+  return Visit(op);
+}
+
 /// Return the size or alignment of the type of argument of the sizeof
 /// expression as an integer.
 mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 4bccf65cceb13..3d1e395d7613c 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -203,3 +203,26 @@ void foo11() {
 
 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
 // OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+
+void foo12() {
+  double _Complex c;
+  double real = __real__ c;
+}
+
+// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c"]
+// CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr, ["real", 
init]
+// CIR: %[[REAL_PTR:.*]] = cir.complex.real_ptr %[[COMPLEX]] : 
!cir.ptr> -> !cir.ptr
+// CIR: %[[REAL:.*]] = cir.load{{.*}} %[[REAL_PTR]] : !cir.ptr, 
!cir.double
+// CIR: cir.store{{.*}} %[[REAL]], %[[INIT]] : !cir.double, 
!cir.ptr
+
+// LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
+// LLVM: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// LLVM: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// LLVM: store double %[[REAL]], ptr %[[INIT]], align 8
+
+// OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT:.*]] = alloca double, align 8
+// OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// OGCG: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// OGCG: store double %[[REAL]], ptr %[[INIT]], align 8

``




https://github.com/llvm/llvm-project/pull/144261
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [CIR] Upstream __real__ for ComplexType (PR #144261)

2025-06-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for __real__ for ComplexType

https://github.com/llvm/llvm-project/issues/141365

---
Full diff: https://github.com/llvm/llvm-project/pull/144261.diff


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+21) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+23) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 75b4d2a637e6e..615a0e7bef556 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -603,6 +603,8 @@ class ScalarExprEmitter : public 
StmtVisitor {
 
   mlir::Value VisitUnaryLNot(const UnaryOperator *e);
 
+  mlir::Value VisitUnaryReal(const UnaryOperator *e);
+
   mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); }
 
   /// Emit a conversion from the specified type to the specified destination
@@ -1891,6 +1893,25 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const 
UnaryOperator *e) {
   return maybePromoteBoolResult(boolVal, cgf.convertType(e->getType()));
 }
 
+mlir::Value ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *e) {
+  // TODO(cir): handle scalar promotion.
+  Expr *op = e->getSubExpr();
+  if (op->getType()->isAnyComplexType()) {
+// If it's an l-value, load through the appropriate subobject l-value.
+// Note that we have to ask E because Op might be an l-value that
+// this won't work for, e.g. an Obj-C property.
+if (e->isGLValue())
+  return cgf.emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc())
+  .getScalarVal();
+
+// Otherwise, calculate and project.
+cgf.cgm.errorNYI(e->getSourceRange(),
+ "VisitUnaryReal calculate and project");
+  }
+
+  return Visit(op);
+}
+
 /// Return the size or alignment of the type of argument of the sizeof
 /// expression as an integer.
 mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 4bccf65cceb13..3d1e395d7613c 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -203,3 +203,26 @@ void foo11() {
 
 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
 // OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 1
+
+void foo12() {
+  double _Complex c;
+  double real = __real__ c;
+}
+
+// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c"]
+// CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr, ["real", 
init]
+// CIR: %[[REAL_PTR:.*]] = cir.complex.real_ptr %[[COMPLEX]] : 
!cir.ptr> -> !cir.ptr
+// CIR: %[[REAL:.*]] = cir.load{{.*}} %[[REAL_PTR]] : !cir.ptr, 
!cir.double
+// CIR: cir.store{{.*}} %[[REAL]], %[[INIT]] : !cir.double, 
!cir.ptr
+
+// LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
+// LLVM: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// LLVM: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// LLVM: store double %[[REAL]], ptr %[[INIT]], align 8
+
+// OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT:.*]] = alloca double, align 8
+// OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr 
%[[COMPLEX]], i32 0, i32 0
+// OGCG: %[[REAL:.*]] = load double, ptr %[[REAL_PTR]], align 8
+// OGCG: store double %[[REAL]], ptr %[[INIT]], align 8

``




https://github.com/llvm/llvm-project/pull/144261
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] f34cb2d - Revert "[GlobalISel] Split Legalizer debug ouput into paragraphs. NFC (#143427)"

2025-06-15 Thread via llvm-branch-commits

Author: Austin
Date: 2025-06-15T17:27:46+08:00
New Revision: f34cb2d084ab06d744620ec8542e12effd45409e

URL: 
https://github.com/llvm/llvm-project/commit/f34cb2d084ab06d744620ec8542e12effd45409e
DIFF: 
https://github.com/llvm/llvm-project/commit/f34cb2d084ab06d744620ec8542e12effd45409e.diff

LOG: Revert "[GlobalISel] Split Legalizer debug ouput into paragraphs. NFC 
(#143427)"

This reverts commit 89f692a24f6a13ae5cf9e37f91abe6f34c403258.

Added: 


Modified: 
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp 
b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 028bffd1bf5a7..83ba71e4c9d49 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -118,7 +118,7 @@ LegalizerHelper::LegalizerHelper(MachineFunction &MF, const 
LegalizerInfo &LI,
 LegalizerHelper::LegalizeResult
 LegalizerHelper::legalizeInstrStep(MachineInstr &MI,
LostDebugLocObserver &LocObserver) {
-  LLVM_DEBUG(dbgs() << "\nLegalizing: " << MI);
+  LLVM_DEBUG(dbgs() << "Legalizing: " << MI);
 
   MIRBuilder.setInstrAndDebugLoc(MI);
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits