[llvm] b490029 - [ConstantFold] Allow all float types in reinterpret load folding

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 21 00:27:00 PST 2022


Author: Nikita Popov
Date: 2022-01-21T09:26:51+01:00
New Revision: b4900296e4a51b0076bac69b31871c7a29efa90f

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

LOG: [ConstantFold] Allow all float types in reinterpret load folding

Rather than hardcoding just half, float and double, allow all
floating point types.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/loads.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c834ecf10791..38c9cc7b9df2 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -557,8 +557,8 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
     // then bitcast the result.  This can be useful for union cases.  Note
     // that address spaces don't matter here since we're not going to result in
     // an actual new load.
-    if (!LoadTy->isHalfTy() && !LoadTy->isFloatTy() && !LoadTy->isDoubleTy() &&
-        !LoadTy->isPointerTy() && !LoadTy->isVectorTy())
+    if (!LoadTy->isFloatingPointTy() && !LoadTy->isPointerTy() &&
+        !LoadTy->isVectorTy())
       return nullptr;
 
     Type *MapTy = Type::getIntNTy(

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
index 43038bcbdbfe..5e28f166b9eb 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
@@ -112,36 +112,44 @@ define i128 @test_i128() {
 }
 
 define fp128 @test_fp128() {
-; CHECK-LABEL: @test_fp128(
-; CHECK-NEXT:    [[R:%.*]] = load fp128, fp128* bitcast ({ i64, i64 }* @g3 to fp128*), align 16
-; CHECK-NEXT:    ret fp128 [[R]]
+; LE-LABEL: @test_fp128(
+; LE-NEXT:    ret fp128 0xL000000000000007B0000000006B1BFF8
+;
+; BE-LABEL: @test_fp128(
+; BE-NEXT:    ret fp128 0xL0000000006B1BFF8000000000000007B
 ;
   %r = load fp128, fp128* bitcast({i64, i64}* @g3 to fp128*)
   ret fp128 %r
 }
 
 define ppc_fp128 @test_ppc_fp128() {
-; CHECK-LABEL: @test_ppc_fp128(
-; CHECK-NEXT:    [[R:%.*]] = load ppc_fp128, ppc_fp128* bitcast ({ i64, i64 }* @g3 to ppc_fp128*), align 16
-; CHECK-NEXT:    ret ppc_fp128 [[R]]
+; LE-LABEL: @test_ppc_fp128(
+; LE-NEXT:    ret ppc_fp128 bitcast (i128 2071796475790618158476296315 to ppc_fp128)
+;
+; BE-LABEL: @test_ppc_fp128(
+; BE-NEXT:    ret ppc_fp128 bitcast (i128 2268949521066387161080 to ppc_fp128)
 ;
   %r = load ppc_fp128, ppc_fp128* bitcast({i64, i64}* @g3 to ppc_fp128*)
   ret ppc_fp128 %r
 }
 
 define x86_fp80 @test_x86_fp80() {
-; CHECK-LABEL: @test_x86_fp80(
-; CHECK-NEXT:    [[R:%.*]] = load x86_fp80, x86_fp80* bitcast ({ i64, i64 }* @g3 to x86_fp80*), align 16
-; CHECK-NEXT:    ret x86_fp80 [[R]]
+; LE-LABEL: @test_x86_fp80(
+; LE-NEXT:    ret x86_fp80 0xKFFFF000000000000007B
+;
+; BE-LABEL: @test_x86_fp80(
+; BE-NEXT:    ret x86_fp80 0xK000000000000007B0000
 ;
   %r = load x86_fp80, x86_fp80* bitcast({i64, i64}* @g3 to x86_fp80*)
   ret x86_fp80 %r
 }
 
 define bfloat @test_bfloat() {
-; CHECK-LABEL: @test_bfloat(
-; CHECK-NEXT:    [[R:%.*]] = load bfloat, bfloat* bitcast ({ i64, i64 }* @g3 to bfloat*), align 2
-; CHECK-NEXT:    ret bfloat [[R]]
+; LE-LABEL: @test_bfloat(
+; LE-NEXT:    ret bfloat 0xR007B
+;
+; BE-LABEL: @test_bfloat(
+; BE-NEXT:    ret bfloat 0xR0000
 ;
   %r = load bfloat, bfloat* bitcast({i64, i64}* @g3 to bfloat*)
   ret bfloat %r


        


More information about the llvm-commits mailing list